by Allen Wyatt
(last updated March 21, 2020)
Liz has several documents, each with multiple tables containing content. These tables are simple two-column tables with varying numbers of rows. Currently, the column widths of the tables vary depending on the content. Liz wants all the tables to have the same column widths (for example, 5.25" for the first column and 1.25" for the second column). She wonders if there is a way to accomplish this other than setting the column widths for each table one at a time.
If, as Liz describes, these are existing documents that contain a bunch of tables, then the only way to accomplish this task is to use a macro. The technique to use has actually been described in a different WordTip, which you can find here:
While the technique described in that tip is applicable to Liz's situation, it can be made even more applicable by simply making a few changes. For instance, Liz indicates that all of the tables have two columns. However, if there is (for some reason) a table or two that have a different number of columns, a macro that expects two columns could play havoc with these other tables. Consider this macro, which simply skips any table that has a different number of columns:
Sub SetTableWidths() Dim t As Table Dim iFixed As Integer Dim iSkipped As Integer Dim sTemp As String iFixed = 0 iSkipped = 0 For Each t In ActiveDocument.Tables If t.Columns.Count = 2 Then t.Columns(1).Width = InchesToPoints(5.25) t.Columns(2).Width = InchesToPoints(1.25) iFixed = iFixed + 1 Else iSkipped = iSkipped + 1 End If Next t sTemp = "Tables Fixed: " & iFixed & vbCr sTemp = sTemp & "Tables Skipped: " & iSkipped MsgBox sTemp End Sub
When you run the macro, it adjusts the width of all two-column tables in the document. When completed, it shows the number of tables that were fixed (the number of two-column tables) and the number of tables that were skipped (those that had fewer or more columns than two).
This macro-based approach works great for documents that already have tables in them. If you are creating new documents, though, you should consider creating a "standard" table and store it as a Building Block. This makes it very easy to put such a table in your document as you are developing it. The way you do this is covered in a different WordTip:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13749) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Office 365.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!
When you get a text file from a program other than Word, tabular information may be formatted with nothing but spaces in ...Discover More
When you create a table that extends beyond a single page, you may want to make sure that the information in a table row ...Discover More
When adding borders and shading to a document's elements, Word allows you to quickly add drop shadows to paragraphs, text ...Discover More