Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Setting a Default Table Border Width.
Written by Allen Wyatt (last updated August 28, 2021)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365
When you insert a table in Word, a border is automatically created for each cell in the table. This border is a single line, one-half point in weight. Unfortunately, Word provides no way for you to change the default line width you use when creating the table. While it is true you can pick a line width in the Borders and Shading dialog box, this weight is reset to one-half point when you insert a new table.
If you want some other line width, such as three-quarters of a point, you have a problem. You must manually select any new table and format the borders, so they are the desired width. If you work with lots of tables, this can quickly become a hassle. You could, of course, create a table style, but applying a table style can give uneven results if all you want to do is change the line width or if you are working with a document where there has been a lot of explicit formatting applied to the tables.
Perhaps the best way around this problem is to write a macro. Even though this may not be the most ideal solution, it certainly is easier than manually changing every table in the document.
The following macro, FixCellBorders, steps through every cell in every table in your document and makes sure the minimum line weight is three-quarters of a point. It does this by checking out the current line settings, and then making the adjustment only if necessary.
Sub FixCellBorders() On Error Resume Next ' Work through all tables in document For Each objTable In ActiveDocument.Tables ' Work through all cells in each table For Each objCell In objTable.Range.Cells ' Work through all borders in each cell For Each objBorder In objCell.Borders ' Check if line weight is less than 0.75 pt If objBorder.LineWidth = wdLineWidth025pt _ Or objBorder.LineWidth = wdLineWidth050pt Then ' too thin, change it objBorder.LineWidth = wdLineWidth075pt End If Next objBorder Next objCell Next objTable End Sub
As you can imagine, the macro is not terribly fast since it looks at all four borders for every cell in every table of your document. The advantage, however, is that the macro will only modify the weight of any cell border that is at one-quarter or one-half point. This means that any manual formatting you have done for different line widths will not change.
If you are looking for a bit faster macro, the following (FixTableBorders) will do the trick. Instead of looking at individual cells, it works on entire tables. The difference, however, is that it resets every border of every table to three-quarters of a point, using a single line. If this fits your needs, however, it is definitely the easier (faster) way to go.
Sub FixTableBorders() On Error Resume Next For Each objTable In ActiveDocument.Tables With objTable With .Borders(wdBorderLeft) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth075pt End With With .Borders(wdBorderRight) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth075pt End With With .Borders(wdBorderTop) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth075pt End With With .Borders(wdBorderBottom) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth075pt End With With .Borders(wdBorderHorizontal) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth075pt End With With .Borders(wdBorderVertical) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth075pt End With End With Next objTable End Sub
Note:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13081) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Setting a Default Table Border Width.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
Need to jump to a particular row in a table? Word provides an easy way to jump to all sorts of things, but it doesn't ...
Discover MoreWord allows you to insert simple formulas, using fields, in table cells. If you want to see these formulas in their ...
Discover MoreWord allows you to format your text using different languages. If you are working with a right-to-left language, you may ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2022-09-06 09:26:15
Nancy
Hi Allen,
I've used your script for the LineWidth, if objBorder is 0.25 or 0.50, then change to 0.75. Me I've adapted it to 0.50 or 0.75, change to 1.00 pt.
It worked only if I've removed the Option Explicit.
I've tested by inactivate the Option Explicit, but then I get an error message for LineWidth, cause if you put a dot beside objBorder on the bottom, you will not find LineWidth. So I don't know why with by ignoring Option Explicit it works eventhough LineWidth is not findable.
Can you give me a script with the Option Explicit to every cell? Cause I've notice some people do put 0.50 and 0.75 on the same table. Would be nice to fix those table.
Thanks,
Nancy
2021-08-28 10:12:53
Ken Endacott
The following macro allows you to specify the line style and width. Set the variables Lstyle and Lwidth to suit using the available options.
This macro will only change the tables selected. If you want to alter all tables in the document then CTRL + A to select all before running the macro.
Sub FixTableBorders2()
Dim objTable As Table
Dim Lstyle As Long
Dim Lwidth As Long
Dim k As Long
' --- there are 25 line styles available ---
' --- Search internet for WdLineStyle to see others ---
Lstyle = wdLineStyleSingle
' --- Line width options are: wdLineWidth025pt, wdLineWidth050pt ---
' --- wdLineWidth075pt, wdLineWidth100pt, wdLineWidth150pt ---
' --- wdLineWidth225pt, wdLineWidth300pt, wdLineWidth450pt, wdLineWidth600pt ---
Lwidth = wdLineWidth075pt
On Error Resume Next
For Each objTable In Selection.Range.Tables
With objTable
For k = -6 To -1
With .Borders(k)
.LineStyle = Lstyle
.LineWidth = Lwidth
End With
Next k
End With
Next objTable
End Sub
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 © 2024 Sharon Parq Associates, Inc.
Comments