h1

Word: Macro to autofit all tables to the window size

February 17, 2019

Some 11 years ago, I published a macro for setting all tables to autofit to the width of the page (i.e. within the page margins). Here’s a slightly different version written by Stefan Blom in 2012—his original macro was called SetFitToWin, but I’ve modified that for my purposes so I can easily see from the name what this macro does:

Sub SetTableToFitToWindow()
' From Stefan Blom (April 2012):
' https://answers.microsoft.com/en-us/msoffice/forum/all/set-table-to-default-autofit-to-window/a0fffbad-0081-436c-b932-decf404cd88f
' Adapted title (was SetFitToWin), Rhonda Bracey, Cybertext Consulting, Feb 2019

    Dim t As Table
    For Each t In ActiveDocument.Tables
        t.AutoFitBehavior wdAutoFitWindow
    Next t
End Sub

The same caveats apply as per the original blog post in 2008—this changes ALL your tables, so test on a copy of your document first to make sure you don’t inadvertently change tables you didn’t want to change.

[Links last checked February 2019]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: