Thread: [Solved] Resize and center tables
View Single Post
 
Old 06-08-2012, 09:25 AM
Ulodesk Ulodesk is offline Windows 7 64bit Office 2010 64bit
Word 2013 Expert Cert
 
Join Date: Sep 2009
Location: Virginia
Posts: 872
Ulodesk is on a distinguished road
Default Resize and center tables

I have a macro that resizes all tables in a document to margin width, but it doesn't center them, which is also part of our style. I have tried to find the right code in VBA, starting a line with oTbl. and seeing what optins come up, but it's pure trial and error -- and all errors. There doesn't seem to be a horizontal alignment tag... Here's what I have:


Code:
 
Sub ResizeAllTables()
    Dim oTbl As Table
    For Each oTbl In ActiveDocument.Tables
        oTbl.AutoFitBehavior wdAutoFitFixed
        With ActiveDocument.PageSetup
            oTbl.PreferredWidth = .PageWidth - .LeftMargin - .RightMargin
        End With
    Next oTbl
End Sub
Reply With Quote