Adding a Full-Width Line in a Macro

Written by Allen Wyatt (last updated May 17, 2022)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and 2021


When typing in a document, Drew can type three dashes and when he presses Enter, Word converts the dashes to a full-width line. He wonders how he can do this within a macro.

The feature in Word that results in converting three dashes into a full-width line is AutoFormatting. It is just one of the things that goes on in the background as you type—Word is continually analyzing the characters you enter and the actions you take, and then "helping you out" by doing the conversion automatically. In this case, you just need to—on a new line—type three dashes and press the Enter key. The conversion to a full-width line is immediately done.

How AutoFormat does this is actually a bit interesting. You might think that you could record a macro to see what AutoFormat does, but you cannot. When you turn on the Macro Recorder, type three dashes, and press Enter, AutoFormat does absolutely nothing—the dashes remain and no line appears.

So, it is helpful to use a different detective method to figure out what is going on. What I did was to open a brand-new document and make sure that non-printing characters were displayed. (This is necessary so you can see where paragraph marks—hard returns—are within the document.) I then typed some numbers so I could reference the paragraphs, but I made sure there was an "empty" paragraph in the middle. (See Figure 1.)

Figure 1. Setting up for the AutoFormat test.

The empty paragraph (between paragraphs 4 and 5) is where I'm going to type the three dashes to test out AutoFormat. When I type them and then press Enter, the result is an underline on paragraph 4. (See Figure 2.)

Figure 2. An underline added by AutoFormat.

You can tell that the underline is on paragraph 4 by putting the insertion point on that line and displaying the Borders and Shading dialog box. When you display the dialog box with the insertion point on any other line, there is no border—it is only on paragraph 4.

I then added an empty paragraph between paragraphs 7 and 8 in order to see what AutoFormat does when I type three underscores and press Enter. When I did this, the exact same thing happened as noted earlier. The only difference was that the border added to paragraph 7 was of a heavier weight (it was thicker) then the border added to paragraph 4. (See Figure 3.)

Figure 3. An underline added by typing three underscores.

Thus, typing three dashes and three underscores results in a border added to the previous paragraph (after the paragraph with the dashes or underscores is deleted), with the only difference being the weight of the underscore. Further, if you look closely at the Borders and Shading dialog box in the above instances, you'll notice that when you type three dashes, AutoFormat uses a border width of 0.75 points and if you type three underscores it uses a border width of 1.50 points.

Replicating this behavior in a macro is relatively easy. You don't need to actually add three dashes or underscores and then delete them and their paragraph; that would be superfluous. Instead, the macro can simply move to the previous paragraph and set the bottom border for that paragraph.

Sub BottomBorder()
    Selection.MoveUp Unit:=wdParagraph, Count:=1
    With Selection.Borders(wdBorderBottom)
        .LineStyle = wdLineStyleSingle
        .LineWidth = wdLineWidth075pt
        .Color = wdColorAutomatic
    End With
End Sub

If you want to mimic AutoFormat's behavior when you type three underscores and press Enter, all you need to do is change the wdLineWidth075pt enumeration in the above macro to wdLineWidth150pt.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13537) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and 2021.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Automatically Numbering Rows

Adding row numbers to a column of your worksheet is easy; you just need to use a formula to do it. Here's a quick look at ...

Discover More

Removing Spaces

Need to get rid of spaces in a range of cells? There are two ways you can approach the task, as described here.

Discover More

Returning Blanks with VLOOKUP

Normally the VLOOKUP function returns a value, and if it can't return a value it returns a zero. Here's how you can use ...

Discover More

Do More in Less Time! An easy-to-understand guide to the more advanced features available in the Microsoft 365 version of Word. Enhance the quality of your documents and boost productivity in any field with this in-depth resource. Complete your Word-related tasks more efficiently as you unlock lesser-known tools and learn to quickly access the features you need. Check out Microsoft 365 Word For Professionals For Dummies today!

More WordTips (ribbon)

Printing Shortcut Key Assignments from a Macro

Need to know what shortcut keys are defined? You can use a single macro command line to print out the definitions.

Discover More

Running Macros Based on Keywords

Wouldn't it be great if Word could execute a macro every time someone typed in a particular keyword or phrase? Word may ...

Discover More

Determining the Horizontal Position of the Insertion Point

Need to figure out how far the insertion point is from the left margin? You can do so by using this small macro that ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is seven more than 2?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

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.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.