SetWidth Method
Applies To
Cell object, Cells collection object, Column object, Columns collection object.
Description
Sets the width of rows or cells in a table.
Syntax
expression.SetWidth(ColumnWidth, RulerStyle)
expression Required. An expression that returns a Cell, Cells, Column, or Columns object.
ColumnWidth Required Single. The width of the specified column or columns, in points.
RulerStyle Required Long. Controls the way Word adjusts cell widths. Can be one of the following WdRulerStyle constants.
Constant | Description |
|
wdAdjustFirstColumn | Preserves the column width by narrowing cells in the first column only. |
wdAdjustNone | Preserves the width of all columns other than the ones that contain the specified cells. This is the default value. |
wdAdjustProportional | Preserves the column width by adjusting all cells to the right of the specified column. |
wdAdjustSameWidth | Preserves the column width by narrowing all cells in the specified columns, assigning the same width to all of them. |
See Also
AutoFit method, AutoFormat method, Columns property, DistributeWidth method, SetHeight method, SpaceBetweenColumns property, Width property.
Example
This example creates a table in a new document and sets the width of the first cell in the second row to 1.5 inches. The example preserves the widths of the other cells in the table.
Set newDoc = Documents.Add
Set myTable = newDoc.Tables.Add(Range:=Selection.Range, NumRows:=3, _
NumColumns:=3)
myTable.Cell(2,1).SetWidth ColumnWidth:=InchesToPoints(1.5), _
RulerStyle:=wdAdjustNone
This example sets the width of the cell that contains the insertion point to 36 points. The example also narrows the first column to preserve the position of the right edge of the table.
If Selection.Information(wdWithInTable) = True Then
Selection.Cells(1).SetWidth ColumnWidth:=36, _
RulerStyle:=wdAdjustFirstColumn
Else
MsgBox "The insertion point is not in a table."
End If