Placing the First Two Words from the Following Page In the Footer

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


Dawn would like the footer on each page in her document to contain the first two words that appear on the following page in the document. If the pagination changes, then of course the footer should update to reflect whatever two words are then at the top of the following page.

This is a tough problem for several reasons. Word allows you to rather easily create "dictionary style" headers or footers, using the STYLEREF field. However, that field always refers to the first or last usage of a style on the page where the STYLEREF field appears. In Dawn's case, she wants words from the next page, not the current page.

The biggest problem, though, is the desire for the footer to update, dynamically, as editing occurs in the document. We've not been able to find a way to do this with the tools that Word provides. You can, if desired, create a macro that sets the footers, but there is a catch—because each page will have a different footer, you'll need to add a section break to the end of each page. This, of course, means that if you later add or delete text, you'll need to delete section breaks so they again match up with the end of each page.

Sound complicated? It can be, particularly if you have a document with many pages because such a document will require many section breaks. Even so, a macro like the following will help accomplish what you want:

Sub FillFooter()
    Dim iPage As Integer
    Dim iSec As Integer
    Dim sFText As String
    Dim sTemp As String

    sFText = "See next page for this: "

    Selection.HomeKey Unit:=wdStory     ' Go to beginning of document

    ' Use Find and Replace to get rid of all section breaks
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^b"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = False
        .MatchFuzzy = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    iSec = 1            ' Only 1 section now in document
    For iPage = 1 To Selection.Information(wdNumberOfPagesInDocument) - 1
        ' Figure out first two words on "next page"
        Selection.GoTo what:=wdGoToPage, which:=wdGoToNext, Name:=iPage + 1
        Selection.MoveRight Unit:=wdWord, Count:=2, Extend:=wdExtend
        sTemp = Trim(Selection)
        While Asc(Right(sTemp, 1)) < 65
            ' Word counts punctuation, tabs, etc. as a word, so grab another word
            Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
            sTemp = Trim(Selection)
        Wend

        Selection.Collapse      ' Now at beginning of page again
        Selection.MoveUp Unit:=wdParagraph
        Selection.InsertBreak Type:=wdSectionBreakContinuous

        ' Set text for page footer
        With ActiveDocument.Sections(iSec).Footers(wdHeaderFooterPrimary)
            .LinkToPrevious = False
            .Range.Text = sFText & sTemp
        End With
        iSec = iSec + 1
    Next iPage
End Sub

The macro first removes all section breaks from the document, then it goes through each page of the document and figures out the first two words of each. It then steps back a paragraph and adds a continuous section break and finally sets the footer for that section to be equal to the desired text. You should note that the footer is set equal to whatever is in the sFText variable followed by the first two words of the next page.

Understand that a macro such as this provides a "static" approach to the desired footer. This means that if you end up making changes to your document, you'll want to once again run the macro to update the footers.

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 (2835) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, 2021, 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

Unwanted Numbering on Pasted Tables

When pasting text from another document or from the Web you can have unexpected characters sometimes show up. Many of ...

Discover More

Inserting Video into Worksheets

You can add all sorts of objects to your workbooks, including video clips. Here's the pros and cons (along with the ...

Discover More

Item Not Available in Library

When sharing workbooks with others, you may find that the macros in those workbooks may not work as you expect. This tip ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2019. Spend more time working and less time trying to figure it all out! Check out Word 2019 For Dummies today!

More WordTips (ribbon)

Word Count for Headers and Footers

Getting a word count for an entire document is rather easy. If you want a word count for a special part of a document ...

Discover More

Keyboard Shortcut to Access Header and Footer

Some folks like to avoid using the mouse whenever possible, preferring to leave their hands on the keyboard. If you are ...

Discover More

Using Last-page Headers and Footers

Headers and footers add a nice touch to your documents, particularly if they are printed. You may want Word to use a ...

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 three less than 4?

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.