nic*_*nda 3 vba ms-word word-2010
以下是我目前用于将大型文档重新格式化为公司品牌的宏的摘录.
Selection.Tables(1).Select
Selection.Columns(1).Width = CentimetersToPoints(5.46)
Selection.Columns(2).Width = CentimetersToPoints(10.92)
Selection.Rows.HeightRule = wdRowHeightAtLeast
Selection.Rows.Height = CentimetersToPoints(0.8)
Run Code Online (Sandbox Code Playgroud)
我得到的文件现在有三个列表和两个列表,我希望这些列的所有列都是5.46宽,而我需要两个列表以坚持我上面指定的宽度来保持所有格式看起来都不错.
我想放入一个"if,then"类型的语句,说明如果表有三列这样做,如果表有两个,那么这样做但我不知道如何从2列表中识别3个列表.
编辑:更新以处理具有不均匀列宽的行.
Dim tbl As Table
Dim rw As Row
Set tbl = ActiveDocument.Tables(1)
For Each rw In tbl.Rows
With rw
.Cells(1).Width = CentimetersToPoints(5.46)
If .Cells.Count = 2 Then
.Cells(2).Width = CentimetersToPoints(10.92)
ElseIf .Cells.Count = 3 Then
.Cells(2).Width = CentimetersToPoints(5.46)
.Cells(3).Width = CentimetersToPoints(5.46)
Else
'what do do if not 2 or 3?
End If
.HeightRule = wdRowHeightAtLeast
.Height = CentimetersToPoints(0.8)
End With
Next rw
Run Code Online (Sandbox Code Playgroud)