Orson has a document that is about 300 pages long and contains more than a hundred tables. The text area within the document is 6.5 inches. Orson needs a way to easily find any table that is less than 6.25 inches wide or more than 6.5 inches wide. This doesn't seem to be something he can do with Find and Replace, so he wonders if he will need a macro.
The short answer is yes, a macro is required to perform this type of analysis. Fortunately, the macro doesn't need to be very complex. It simply needs to step through each table, calculate the table width, and then make a determination of what to do if the width is outside of Orson's target width. The following macro performs exactly those steps:
Sub AnalyzeTableWidths()
Dim tbl As Table
Dim tblWidth As Double
Dim tblCount As Long
Dim sMsg As String
Dim pg As Long
Dim docReport As Document
sMsg = ""
tblCount = 0
For Each tbl In ActiveDocument.Tables
tblCount = tblCount + 1
tblWidth = tbl.PreferredWidth / 72
If tblWidth < 6.25 Or tblWidth > 6.5 Then
pg = tbl.Range.Information(wdActiveEndPageNumber)
If sMsg = "" Then
sMsg = "Tables out of range (< 6.25"" or > 6.5""):"
sMsg = sMsg & vbCrLf & vbCrLf
End If
sMsg = sMsg & "¥ Table #" & tblCount & " on page " & pg & _
" (Width: " & Format(tblWidth, "0.00") & " in.)" & vbCrLf
End If
Next
' Show the results
If sMsg = "" Then
sMsg = "All tables are within the allowed width (6.25"" - 6.5"")."
Else
Set docReport = Documents.Add
docReport.Content.Text = sMsg
sMsg = "Scan complete! A summary report has been created "
sMsg = sMsg & "in a new document."
End If
MsgBox sMsg, vbInformation, "Done"
End Sub
Note that the macro puts together a report in the sMsg string as it steps through each table. The report includes not only the width of the table, but also the page on which the table is located. When complete, if there is something in the report, then a new document is created and the report is placed there. If no tables were found outside the target width, then a message box to that effect is displayed.
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13992) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365.
Discover the Power of Microsoft Office This beginner-friendly guide reveals the expert tips and strategies you need to skyrocket your productivity and use Office 365 like a pro. Mastering software like Word, Excel, and PowerPoint is essential to be more efficient and advance your career. Simple lessons guide you through every step, providing the knowledge you need to get started. Check out Microsoft Office 365 For Beginners today!
For those times when you remove the borders from your tables, Word provides a way that you can display non-printing ...
Discover MoreIf you import information into a document from another program, the values you import may not be exactly to your liking. ...
Discover MoreInsert a picture into a table cell, and you may quickly find that the table is no longer the size you expected. Here's ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2026-08-09 09:37:16
beepee
Addendum to my comment 2026-08-08 11:51:35
I am still 'playing' trying to resolve this.
Having ventured into Copilot for some help I came up with the following...
The code snippet below, gets me the right results by adding column widths together to arrive at the table width.
For LoopCount = 1 To tblCount
Set tbl = ActiveDocument.Tables(LoopCount)
TableWidth = 0
For Each col In tbl.Columns
TableWidth = TableWidth + col.Width
Next col
With the original macro:
Hovering over - tbl.PreferredWidth – I get – TblPreferredWidth = 9999999 – I assume this is a default and maybe I need a - Set - statement somewhere, and that is what is scuppering the .PreferredWidth value?
2026-08-08 11:51:35
beepee
This could be really handy but...
I am using Windows 11 Office (Word) 2021
and with differnt sized tables in a document I get the following report:
¥ Table #1 on page 7 (Width: 138888.88 in.)
¥ Table #2 on page 37 (Width: 138888.88 in.)
¥ Table #3 on page 37 (Width: 138888.88 in.)
¥ Table #4 on page 57 (Width: 138888.88 in.)
¥ Table #5 on page 59 (Width: 138888.88 in.)
Obviously very wrong - I thought maybe my dimension settings in cm may be a problem. I reset this to inches with the same result. - even after a Close and re Open operation!
Any help please!
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2026 Sharon Parq Associates, Inc.
Comments