iantist
iantist

Reputation: 843

How to change the font size of all tables in a word document using a vba macro

I have a word document with a lot of tables. I would like a macro which changes the fonts size of all tables to 10, autofits each table to the window and distributes the columns evenly. I can accomplish the last two goals using the below code, but not sure how to change the font size. Any help would be greatly appreciated.

Sub changetables()
Dim tbl As Table
For Each tbl In ActiveDocument.Tables
    tbl.AutoFitBehavior wdAutoFitWindow
    tbl.Columns.DistributeWidth

Next

End Sub

Upvotes: 1

Views: 11747

Answers (2)

Douglas Quintanilla
Douglas Quintanilla

Reputation: 1

Just change .size to .name, as in tbl.Range.Font.Name = "Calibri"

This should also work for whatever font name you wish to use by replacing Calibri within the double quotes to your desired font name.

Upvotes: 0

Jean-Pierre Oosthuizen
Jean-Pierre Oosthuizen

Reputation: 2693

For your exact code use

   tbl.Range.Font.Size = 12

I have retyped a few things to show better naming and spacing etc.

 Sub changetables()

      Dim CurrentTable As Table

      For Each CurrentTable In ActiveDocument.Tables

           With CurrentTable

                .AutoFitBehavior wdAutoFitWindow
                .Columns.DistributeWidth
                .Range.Font.Size = 12
           End With

      Next CurrentTable

 End Sub

Upvotes: 4

Related Questions