在Word文档表上分配列宽

时间:2018-09-25 14:22:17

标签: vba ms-word word-vba

我的目标是转到Word文档的顶部,找到第6个表,然后将该表设置为“ Arial”和9号字体,并分配列宽。

问题在于它不分配列宽,而分配其他两个宽度。

Sub TableFormat()

Selection.GoTo wdGoToPage, wdGoToAbsolute, 1
Selection.GoTo What:=wdGoToTable, Which:=GoToNext
Selection.GoTo What:=wdGoToTable, Which:=GoToNext
Selection.GoTo What:=wdGoToTable, Which:=GoToNext
Selection.GoTo What:=wdGoToTable, Which:=GoToNext
Selection.GoTo What:=wdGoToTable, Which:=GoToNext
Selection.GoTo What:=wdGoToTable, Which:=GoToNext
    Selection.Tables(1).Select
    Selection.Font.Name = "Arial"
    Selection.Font.Size = 9
       If Selection.Cells.Count >= 2 Then
          Selection.Cells.DistributeWidth
       End If
End Sub

2 个答案:

答案 0 :(得分:4)

这应该为您解决问题,而无需疯狂地Select进行:)

Sub TableFormat()
    With ActiveDocument.Tables(6)
        With .Range.Font
            .Name = "Arial"
            .Size = 9
        End With

        If .Columns.count > 1 Then .Columns.DistributeWidth
    End With
End Sub

答案 1 :(得分:0)

Cells.DistributeWidth更改为Columns.DistributeWidth