Microsoft Word Macro to Tidy Up All Tables
Microsoft Word has capability to automatically arrange table's row width and column height.
The reformatted tables are simply better than manual arrangement and it works on tables containing merged columns.
I created Word macro below that will automatically reformat all tables in single macro execution.
It resizes all cells' width and height to fit the content so the table takes least vertical space while maximizing available horizontal space.
This makes the table contents are easier to be read.
To create the macro, open View ribbon in Microsoft Word then click Macro > View Macro.
Type TidyTable in Macro Name then click Create.
Enter the macro code text below into the editor then Save and close the macro editor window.
Sub TidyTable() Options.ReplaceSelection = True For Each aTable In ActiveDocument.Tables With aTable .TopPadding = InchesToPoints(0) .BottomPadding = InchesToPoints(0) .LeftPadding = InchesToPoints(0.03) .RightPadding = InchesToPoints(0.03) .Spacing = 0 .AllowPageBreaks = True .AllowAutoFit = True .PreferredWidthType = wdPreferredWidthPercent .PreferredWidth = 100 .Columns.PreferredWidthType = wdPreferredWidthAuto .Columns.PreferredWidth = 0 .Rows.AllowBreakAcrossPages = True .Rows.HeightRule = wdRowHeightAuto .Rows.Height = 0 .Rows.Alignment = wdAlignRowLeft .Rows.LeftIndent = InchesToPoints(0) .Rows.WrapAroundText = False .Select Selection.Cells.VerticalAlignment = wdCellAlignVerticalTop On Error Resume Next .Rows(1).Cells.VerticalAlignment = wdCellAlignVerticalCenter End With Next aTable End Sub
After then, create shortcut button to the macro.
I usually put it as Quick Access Toolbar button, instead of Ribbon button.
Click on Quick Access' Customize button, select More Commands then add the TidyTable macro.
To apply the macro, select a table then click the TidyTable's Quick Access shortcut button.
What the Macro Does?
Set table's width to 100% of page width, remove wrapping, set alignment to left, etc.
Set cell's vertical alignment to Top, except first row is set to Center.
Disable manual column's width setting.
Disable manual row's height setting.
Sample Word file is available in here.
Comments