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

Adding Text to an Envelope

Need to customize the way that Word prints envelopes? There are a couple of approaches you can use, as discussed in this tip.

Discover More

Word Link to Create a New Excel Workbook

It's easy to create and include links in your documents to other sources, in and out of Word. There are some limitations ...

Discover More

Making Phone Numbers into Active Links

Want to use phone numbers in your documents and have those numbers be clickable links? This tip discusses all the ins and ...

Discover More

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!

More WordTips (ribbon)

Dissecting a String

Want to pull a string apart in a macro? It's easy using the string functions introduced in this tip.

Discover More

Saving Changes when Closing

If you write a macro that makes changes to a document, you may want that macro to save those changes. There are several ...

Discover More

Detecting an Open Dialog Box

Macros can be used to perform all sorts of tasks within Word. Some tasks can even occur at whatever time interval you ...

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 five more than 3?

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.