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 Word in Microsoft 365


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 Word in Microsoft 365.

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

Fixing Macro Button Behavior in Protected Worksheets

When working with macro buttons, you may run into some bizarre behavior related to the macros without really ...

Discover More

Moving Drawing Objects

Add a drawing object to a worksheet and chances are good you'll need to move it in some way. Here's how to use the mouse ...

Discover More

Condensing and Expanding Headings

When working in Outline view, you'll undoubtedly have the need to expand or condense information under your headings. It ...

Discover More

Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!

More WordTips (ribbon)

Converting Paragraphs to Comments

Want to pull text from a bunch of paragraphs and stuff that text into comments? It's easy to do using the macro presented ...

Discover More

Comparing Strings

When writing a macro, a common task is the need to compare two strings. You can do this by "normalizing" the strings, as ...

Discover More

Determining the Number of Paragraphs in a Document

When using a macro to process a document in some way, you often need to know the number of paragraphs in the document. ...

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

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.