Hi Sparrahart,
The following macro fits all tables in a document to a maximum permitted width of 18cm:
Sub TableResizer()
Application.ScreenUpdating = False
Dim oTableWidth As Single
Dim tTableWidth As Single
Dim oTbl As Table
Dim oCol As Column
' Maximum table width
tTableWidth = CentimetersToPoints(18)
' Exit if there's no tables
If ActiveDocument.Tables.Count = 0 Then Exit Sub
' Test all tables
For Each oTbl In ActiveDocument.Tables
' Calculate the current table's width
oTableWidth = 0
For Each oCol In oTbl.Columns
oTableWidth = oTableWidth + oCol.Width
Next oCol
' Compare against maximum table width
If oTableWidth > tTableWidth Then
' Turn off auto sizing & preferred width for oversize tables
With oTbl
.AllowAutoFit = False
.PreferredWidth = 0
End With
' Scale each column's width to fit
For Each oCol In oTbl.Columns
oCol.Width = oCol.Width * tTableWidth / oTableWidth
Next oCol
End If
Next oTbl
Application.ScreenUpdating = True
End Sub
Depending on the amount of text in each cell, you may end up with some of the tables getting longer. To overcome that, you'd
probably need to reduce the font sizes.
Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------
Sparrahart said:
I have six huge Word 2003 documents with many tables in it that are too wide.
I need to change every one to, say, 18cm wide. Can it be done with a macro
in each doc? I have already changed two documents and it has taken me ages
to select and reduce each table. Again, this will save me precious time and
lots of pain in my right hand.