Shelnes Elie
Shelnes Elie

Reputation: 11

Distribute Column Width on Table of Word Document

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

Upvotes: 0

Views: 852

Answers (2)

Marcucciboy2
Marcucciboy2

Reputation: 3261

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

Upvotes: 5

Kubie
Kubie

Reputation: 1571

Change Cells.DistributeWidth to Columns.DistributeWidth

Upvotes: 0

Related Questions