3

以下是我目前用于将大型文档重新格式化为我们公司品牌的宏的摘录。

    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 个列表。

4

1 回答 1

5

编辑:更新以处理列宽不均匀的行。

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
于 2012-08-24T00:58:40.780 回答