Characters in the Margin Next to Paragraphs

Written by Allen Wyatt (last updated February 14, 2023)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365


1

Ralph writes documents that need specific alpha characters to the left of each paragraph. These letters should appear in the margin, similar to line numbers. The characters are typically the same for the entire document, meaning they don't change from paragraph to paragraph. Ralph wonders if there is a way to automatically insert these characters next to each paragraph.

There are a couple of approaches you could use to accomplish this. First, you could type the alpha character at the beginning of each paragraph and press the Tab key. Then, format the paragraph so that it uses a hanging indent that puts the first line into the left margin a bit. This could be easily done using styles that could be applied to the paragraphs.

If you have lots of paragraphs you want to do this with, it can be tedious to type the alpha character and press Tab for each paragraph. Fortunately, it is easy to create a macro that can take care of the tedium for you.

Sub FmtParagraphs()
    Dim p As Paragraph

    For Each p In ActiveDocument.Content.Paragraphs
        If p.Style = "MyAlpha" Then
            With p.Range
                .InsertBefore "R" & Chr(9)
            End With
        End If
    Next p
End Sub

The macro looks for any paragraph in the document that uses the MyAlpha style. (This assumes that MyAlpha" is the special hanging-indent style you created to effect this approach.) When it finds one, it inserts the letter "R" in front of the paragraph and then a tab character. You could easily modify this macro to check for a different style name or to add a different alpha character.

A similar approach is to define a style that utilizes a modified bulleted list. Instead of using a regular bullet, you could define the list to use the alpha character as a bullet. When applying the style to the paragraphs, the alpha character would appear automatically, and you wouldn't need to type it or the tab to separate it from the main body of the paragraph.

Both approaches mentioned so far work quickly and easily for relatively simple documents. They won't work, however, if your documents include regular numbered or bulleted lists. In that case, you'll need to use a different approach—one that relies on text boxes for the placement of the alpha character.

The reason this approach may be preferable for complex documents is that it doesn't rely on styles. That means you can have a wide variety of numbered and bulleted lists in your documents, but still have the alpha characters positioned to the left of each paragraph, in the margin. Further, the text boxes can be formatted so that they are anchored to each paragraph and move with the paragraph as Word repaginates the document.

Of course, if you have a document that has 300 paragraphs in it, adding text boxes to each paragraph can be tedious, not to mention excruciating when you start to format each text box. Again, macros can help to relieve the tedium. The following macro can be used to automatically copy a selected text box to all the other paragraphs in a document.

Sub TextBoxesInMargin()
    Dim aShape As Shape
    Dim aPara As Paragraph
    Dim j As Long
    Dim shpTop As Single
    Dim shpLeft As Single
    Dim aRange As Range

    If ActiveDocument.Shapes.Count = 0 Then GoTo noTextbox
    If Selection.ShapeRange.Count <> 1 Then GoTo noTextbox

    Set aShape = Selection.ShapeRange(1)
    With aShape
        If .Type <> msoTextBox Then GoTo noTextbox
        If aShape.RelativeVerticalPosition <> wdRelativeVerticalPositionParagraph Then
            MsgBox "The text box must be positioned relative to a paragraph"
            Exit Sub
        End If
        shpTop = .Top
        shpLeft = .Left
        aShape.Select
        Selection.Copy
    End With

    For Each aPara In ActiveDocument.Paragraphs
        Set aRange = aPara.Range
        If Len(aRange.Text) > 1 Then ' only non blank paragraphs
            aRange.Select
            Selection.Paste
            Selection.ShapeRange.Top = shpTop
            Selection.ShapeRange.Left = shpLeft
        End If
    Next aPara
    Exit Sub

noTextbox:
    MsgBox "Text box is not selected"
End Sub

To use the macro, format a single small text box to hold your alpha character. Make sure the text box is anchored to the paragraph that you place it beside and that its position is correct relative to the paragraph. Once the text box looks just the way you want it to look, select it and then run the macro. The text box is copied and pasted beside every other paragraph in the document.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (12738) 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

Getting Rid of Persistent Templates

Word uses an open interface that allows add-ons and other programs to expand the way that Word works. Sometimes remnants ...

Discover More

Seeing Excel's Program Window

Have you ever opened Excel to find that the window you saw yesterday is not the same as it is today? Sometimes, for ...

Discover More

Patterns of Numbers with a Formula

Want to create a sequential pattern using formulas? It's easy to do if you take a look at how your data repeats. This tip ...

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)

Hanging Indent Shortcut

You can use the tools on the ribbon to adjust the indent applied to a paragraph. If you want to format a hanging indent, ...

Discover More

Turning Off Paragraph Hyphenation

Need to make sure that a particular paragraph never has any hyphenated words in it? You can make sure that Word won't ...

Discover More

Creating a Double Hanging Indent

A hanging indent is a type of paragraph formatting in which all lines of the paragraph are indented from the left margin ...

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

2023-10-27 06:38:03

Tim McLaughlin

Hi Allen,

I wonder if you could modify the above code to create a macro that would automatically insert paragraph numbers into the margin of a word doc. I tried using your code and inserted a number list into the text box rather that an alpha and I had partial success. I know next to nothing about VBA but it keep on giving me an error code that I did not know how to fix and then it would get stuck half through the document.

I would be wildly excited if you create a macro to do paragraph numbers. because I am really frustrated by Word's inability to do this automatically as it does with line numbers. I am currently finishing a PhD and have three supervisors. I need to be able to refer them to paragraphs in a draft so that we can all communicate know exactly what paragraph we are talking about. Line numbers are just too intrusive.

Not sure if you could help but it would be awesome if it was possible.

Regards,

Tim


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.