Distribute Column Width on Table of Word Document

笑着哭i 提交于 2019-12-11 20:39:14

问题


My goal is to go to the top of the Word document, find the 6th table, and format the table to "Arial" and font 9 and distribute the column width.

The problem is that it doesn't distribute the column width but does the other two.

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

回答1:


This should do the trick for you without all that crazy Selecting :)

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



回答2:


Change Cells.DistributeWidth to Columns.DistributeWidth



来源:https://stackoverflow.com/questions/52500495/distribute-column-width-on-table-of-word-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!