Monday, April 30, 2018

Word Macro: Set all Columns to the Same Width in Every Table


Use the Word macro code below to set every column in every table to the width of the corresponding column in the reference table.


Sub fixColumnWidth()
'
' fixColumnWidth Macro
'
'
Dim refTable As Word.Table
Dim curTable As Word.Table
Dim i As Long
Dim col As Long

Set refTable = ActiveDocument.Tables(7) 'set this to whatever table is the reference table
For i = 2 To ActiveDocument.Tables.Count ' set the start value. Sometimes you want to skip the 1st table (such as Revision History)
  Set curTable = ActiveDocument.Tables(i)
  
  For col = 1 To refTable.Columns.Count
    curTable.Columns(col).Width = refTable.Columns(col).Width
  Next col
Next
End Sub

[Source: Microsoft Community]

No comments:

Post a Comment