AutoFit Method
Applies To
Cells collection object, Column object, Columns collection object.
Description
Changes the width of a table column to accommodate the width of the text without changing the way text wraps in the cells.
Syntax
expression.AutoFit
expression Required. An expression that returns a Column or Columns object.
Remarks
If the table is already as wide as the distance between the left and right margins, this method has no effect.
See Also
Add method (Cells, Rows, and Columns collections), AutoFormat method, Columns property, Height property, HeightRule property, InsertColumns method, SetWidth method.
Example
This example creates a 3x3 table in a new document and then changes the width of the first column to accommodate the width of the text.
Set newDoc = Documents.Add
Set myTable = newDoc.Tables.Add(Range:=Selection.Range, _
NumRows:=3, NumColumns:=3)With myTable
.Cell(1,1).Range.InsertAfter "First cell"
.Columns(1).AutoFit
End With
This example creates a 3x3 table in a new document and then changes the width of all the columns to accommodate the width of the text.
Set newDoc = Documents.Add
Set myTable = newDoc.Tables.Add(Selection.Range, 3, 3)
With myTable
.Cell(1,1).Range.InsertAfter "First cell"
.Cell(1,2).Range.InsertAfter "This is cell (1,2)"
.Cell(1,3).Range.InsertAfter "(1,3)"
.Columns.AutoFit
End With