3

以下は、私が現在使用しているマクロからの抜粋であり、Word の大きな文書を当社のブランドに合わせて再フォーマットしています。

    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)

私が取得したドキュメントには、3 つの列テーブルと 2 つの列テーブルが含まれています。これらのすべての列の幅を 5.46 にしたいのですが、2 つの列テーブルを上記で指定した幅に固定する必要があります。すべてのフォーマットが見栄えがします。

テーブルに3つの列がある場合はこれを行い、テーブルに2つの列がある場合はこれを行うという「if、then」タイプのステートメントを入れたかったのですが、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 に答える