6

MS Word 2016.

I have a large document with hundreds of table. I want to change the table properties of all to untick the 'Preferred width' option.

Is there a way to select all tables to apply this change? Or do I have to select them manually ('select all' doesn't work, since it also highlight normal text that disables table properties)?

2 Answers 2

9

Unfortunately, it is not possible to select all the tables at once with some neat shortcut. Fortunately, even a beginner can use a simple macro and the job is complete in minutes.

For Word 2010 onwards, the 'Developer' tab should already be shown by default, but if not, it is accessed via its the integral ribbon editor. In these applications the ribbon editor is available from File > Options > Customize Ribbon. Tick the Developer checkbox.

enter image description here

Once this is done, click the Developer tab > Macros button

enter image description here

In the new window, type in "Autofit_All_Tables" in the textbox shown, then click the Create button to create a new macro.

enter image description here

Paste the following code into the white text area, fully replacing the existing code.

Sub Autofit_All_Tables()
Application.ScreenUpdating = False
Dim Tbl As Table
For Each Tbl In ActiveDocument.Tables
  Tbl.AutoFitBehavior (wdAutoFitWindow)
  Tbl.AllowAutoFit = True
Next
Application.ScreenUpdating = True
Application.ScreenRefresh
MsgBox "Done", vbOKOnly
End Sub

Then click the green Run arrow (located in the red box in the image).

enter image description here

You should get a little window that says "Done". Close the VBA developer window and sit back in your chair looking pleased with yourself.

Note: If you want to set the width to a percentage fraction of the width between the margins, then create a macro called "Set_Global_Table_Width" and paste in the following code instead. Here the width is set to 100 (i.e. 100%), but you can change it to whatever percentage you want after pasting it into the Word VBA Developer Macro box shown above.

Sub Set_Global_Table_Width()
Dim pT As Word.Table
For Each pT In ActiveDocument.Tables
 pT.PreferredWidthType = wdPreferredWidthPercent
 pT.PreferredWidth = 100
Next
MsgBox "Done"
End Sub
1
  • 1
    This script works well on the latest version of Ms Word. I had 208 tables in my document and they were all edited in one go. (Aug - 4th 2021)
    – GforGIS
    Aug 4, 2021 at 2:23
0

just use the cursor as if you would select the entire line, where you go to the utmost left side of the page, to the margin section until thr cursors tilts to the right side lets say 45 degrees and then you selct/highlight others by also keeping the contro lbutton pressed after the first selection. this is basically selecting multiple lines all over the page and i have just discovered after so many vb script forum reccomendations (not practical) that it works for tables as well. i am just editting a 21 page MSDS ful of tables right now.

1
  • well selecting 100 hundred tables like that isnt practical either :D maybe you just select all and then omit /de-highlight the texts :D Apr 13, 2018 at 9:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .