Cells.AutoFit 方法 (Word)Cells.AutoFit method (Word)

改变表格列宽,使之在单元格文本换行方式不变的情况下,适应文本宽度。Changes the width of a table column to accommodate the width of the text without changing the way text wraps in the cells.

语法Syntax

expressionexpression. AutoFit

expression:必需。expression Required. 代表单元格集合的变量。A variable that represents a 'Cells' collection.

注解Remarks

如果表格的宽度已等于从左边界到右边界的距离,则此方法无效。If the table is already as wide as the distance between the left and right margins, this method has no affect.

示例Example

本示例在新文档中创建一个 3x3 表格,然后调整第一列的宽度,使之与文本的宽度相称。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.

Dim docNew as Document 
Dim tableNew as Table 
 
Set docNew = Documents.Add 
Set tableNew = docNew.Tables.Add(Range:=Selection.Range, _ 
 NumRows:=3, NumColumns:=3) 
With tableNew 
 .Cell(1,1).Range.InsertAfter "First cell" 
 .Columns(1).AutoFit 
End With

本示例在新文档中创建一个 3x3 表格,然后调整所有列的宽度,使之与文本的宽度相称。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.

Dim docNew as Document 
Dim tableNew as Table 
 
Set docNew = Documents.Add 
Set tableNew = docNew.Tables.Add(Selection.Range, 3, 3) 
With tableNew 
 .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

另请参阅See also

单元格集合对象Cells Collection Object