以下是我目前用来重新格式化公司文档中的大文档格式的宏的摘录。
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)
我现在得到的文档包含三个列表以及两个列表,我希望它们具有5.46的所有列宽,而我需要两个列表保持上面指定的宽度以保持所有格式看起来都不错。
我想输入一个“如果,那么”类型的语句,该语句说如果表有三列,则执行此操作,如果表有两列,则执行此操作,但是我不知道如何从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