我在word文档中有多个表,每个表有6列。我想修复所有表中每列的宽度,我有以下脚本。
它一直给我value out of the range
错误。
Sub FormatTables()
Dim t As Table
For Each t In ActiveDocument.Tables
If t.Columns.Count = 6 Then
t.Range.Select
Selection.ClearFormatting
t.AutoFitBehavior _
wdAutoFitWindow
't.Rows.DistributeHeight
t.Rows.WrapAroundText = True
t.Rows.Height = 0.15
t.Columns.DistributeWidth
'tried this way
t.Columns(1).Width = 1.5 'value out of the range
t.Columns(2).Width = 1.5
t.Columns(3).Width = 6.49
t.Columns(4).Width = 6.49
t.Columns(5).Width = 0.8
t.Columns(6).Width = 0.8
'as well as this
t.Columns(1).SetWidth ColumnWidth:=1.5, _
RulerStyle:=wdAdjustProportional 'value out of the range
t.Columns(2).SetWidth ColumnWidth:=1.5, _
RulerStyle:=wdAdjustProportional
t.Columns(3).SetWidth ColumnWidth:=6.49, _
RulerStyle:=wdAdjustProportional
t.Columns(4).SetWidth ColumnWidth:=6.49, _
RulerStyle:=wdAdjustProportional
t.Columns(5).SetWidth ColumnWidth:=0.8, _
RulerStyle:=wdAdjustProportional
t.Columns(6).SetWidth ColumnWidth:=0.8, _
RulerStyle:=wdAdjustProportional
Debug.Print t.Cell(2, 1).Range.Text
End If
Next
End Sub