Word) (Columns.AutoFit 方法

會變更表格欄寬以容納文字的寬度,而不需變更儲存格中文字的換行方式。

語法

expression. AutoFit

需要 expression。 代表 'Columns' 集合的變數。

註解

如果表格的寬度已與介於左右邊界之間的寬度一樣,此方法會沒有作用。

範例

本範例會在新文件中建立一個 3x3 的表格,然後變更第一個欄位的寬度,以容納文字的寬度。

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 的表格,然後變更所有欄位的寬度,以容納文字的寬度。

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

另請參閱

Columns 集合物件

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應