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

Changing Color in WordArt

You can make your document flashier by using WordArt to punch it up. Here's how you can change the color of the text in ...

Discover More

Spacing Before and After Lists

When formatting a document that uses lists, you may want to adjust the space that appears just before and just after the ...

Discover More

Unhiding a Limited Number of Columns

If you have a bunch of hidden columns in your worksheet, you might want to unhide only a portion of those columns. This ...

Discover More

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!

More WordTips (ribbon)

Changing the Format of Existing Dates

There are a myriad of ways in which a date can be formatted: day first, month first, number of digits in the year, etc. ...

Discover More

Modifying Behavior of the Open Dialog Box

The Open dialog box is one that few of us think about, but you can control how it behaves with a little bit of macro ...

Discover More

Creating a Document Font List

If you want a list of all the fonts used in a document, the answer isn't as simple as you may think. This tip uses macros ...

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 0 + 7?

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.