Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Correct Line Numbers When Printing Selections.

Correct Line Numbers when Printing Selections

Written by Allen Wyatt (last updated January 29, 2022)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021


Word allows you to add line numbers to a document. This means exactly what it says—each line in the document is numbered from beginning to end. This can be very helpful when creating special documents, such as legal documents, or when printing a hardcopy for subsequent reference on a line-by-line basis.

When you print a document with continuous line numbers turned on, Word numbers every line from start to finish. However, if you only print a selection (make a selection, display the Print dialog box, and make sure that Selection is specified as what you are printing), then Word doesn't print line numbers correctly. Word numbers the lines in the selection as if it were the entire document—starting at one and proceeding through the selection. One would think that a better approach would be for Word to print the line numbers according to what the selection really represents in the document. For instance, if you selected lines 57 through 72 as your selection and then printed it, Word should print the numbers 57 through 72 at the left side of the printout, rather than 1 through 15.

There is no easy way around this problem, unfortunately. One workaround is to not print selections. (This suggestion may sound more flippant than what is meant.) Instead, print pages. In the print dialog box, specify a page range to print, rather than a selection. Word keeps the line numbering proper, as if you were numbering from the beginning of the document.

Another option is to rely on a macro to do the "dirty work" for you. You can use a macro to reset the beginning line number used for your selection. The following is a simple macro that asks you for a beginning line number, and then prints your selection using that line number as the first number printed at the left. (Note that this macro doesn't start printing with the line number you specify—it uses the number you specify as the starting line number of your selection.)

Sub LineNumbersPrint()
    Dim LineNumberStart As Integer
    On Error GoTo GetOut

    LineNumberStart = InputBox("First line number for printout?", _
      "Line Numbers Printout")

    With ActiveDocument.PageSetup
        With .LineNumbering
            .Active = True
            .StartingNumber = LineNumberStart
        End With
    End With

    ActiveDocument.PrintOut , Range:=wdPrintSelection

    With ActiveDocument.PageSetup
        With .LineNumbering
            .Active = True
            .StartingNumber = 1
        End With
    End With

GetOut:
End Sub

Using this macro assumes that you look up the starting line number of your selection before you actually print. This can be done using the Print Preview feature of Word, but can get tiresome after a while. If you do quite a bit of selection printing, the following macro will be of more interest to you. It is more complex, but it automatically determines the proper line number to use at the start of the selection, and then prints the selection.

Sub Correct_Line_Numbers()
    Dim myRng As Range
    Dim StartRng As Range
    Dim iCount As Integer

'if you include the paragraph mark in your selection, then Word
'prints the subsequent line number; not the entire line, just the
'line number; therefore, if the last character of the current
'selection is a paragraph mark, then move the end position of
'the selection to the left by one character
    If Selection.Characters.Last = Chr(13) Then
        Selection.MoveEnd Count:=-1
    End If

    'set the current selection to a variable
    Set myRng = Selection.Range

    'set the start of the document to a variable
    Set StartRng = ActiveDocument.Paragraphs(1).Range

    With Selection
        'go to the beginning of the line for the current selection and
        'set the iCount variable so that it counts the current line
        .HomeKey unit:=wdLine
        iCount = 1

        'if the cursor is not at the beginning of the document
        'then move the cursor up by one line
        'increment iCount by one each time the cursor is not at
        'the beginning of the document
        While Not Selection.InRange(StartRng)
            .MoveUp unit:=wdLine
            iCount = iCount + 1
            'if the cursor is in a table, then the macro should
            'reduce iCount; Word counts an entire table as one line
            If Selection.Rows.Count > 0 Then
                iCount = iCount - 1
            End If
        Wend
    End With

    'reset the starting line number so that it equals the
    'number of times the cursor was moved up by a line
    ActiveDocument.PageSetup.LineNumbering.StartingNumber = iCount

    'reselect the original selection
    myRng.Select

    'print out only the original selection
    ActiveDocument.PrintOut Range:=wdPrintSelection

    'reset the line number(by "undoing" the last two actions
    '[fields update and change line number])
    'so that line numbering begins at one
    ActiveDocument.Undo
    ActiveDocument.Undo

    'reselect the original selection
    myRng.Select
End Sub

There is one caveat with this macro. If you have hidden text within your document, and that hidden text is displayed but is not set up to print out, then this macro still counts those lines of text as if they would print. In other words, the macro assumes you are printing the hidden text if you have it displayed on-screen.

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 (8520) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Word here: Correct Line Numbers When Printing Selections.

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

Comments Use Tiny Font when Printed

When you print out your documents, do any comments in the document appear very tiny on the printout? It could be because ...

Discover More

Automatic Non-breaking Spaces in Dates

It drives some people crazy to have a date break across two lines. If you find yourself in this mindset, then you'll ...

Discover More

ExcelTips Ribbon 2022 Archive (Table of Contents)

ExcelTips is a weekly newsletter that provides tips on how to best use Microsoft's spreadsheet program. At the ...

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)

Adding Line Numbers

Many types of documents, such as legal documents, require the use of line numbers to make it easier to identify specific ...

Discover More

Numbering Only Certain Lines

Need to add line numbers to a document? Word provides an easy way to add them, but some of the controls that configure ...

Discover More

Line Numbering and Tables

Some types of documents (such as legal documents) may require that individual lines of text be numbered. If you use ...

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 eight 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.