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

Written by Allen Wyatt (last updated January 4, 2021)
This tip applies to Word 2007, 2010, 2013, and 2016


4

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 similar to 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 pack 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, and 2016.

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

Copying Paragraph Formatting with the Mouse

When you get one paragraph formatted just the way you want, you might want to copy that formatting so it can be applied ...

Discover More

Colorizing Charts

Need to change the color of different parts of your chart? It's easy to do when you apply the technique described in this ...

Discover More

Embedding Your Phone Number in a Document

One way you can designate your responsibility for a document is to add your phone number to it. There is no need to add ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More WordTips (ribbon)

Keeping Centered Headers and Footers Centered

Headers and footers provide a nice final touch for your printed documents. If you want to expertly align text in those ...

Discover More

Positioning Headers and Footers

Headers and footers can add a finishing touch to your printed documents. Here's how you can position those headers and ...

Discover More

Making Wider Footer Margins

Want the margins used in your footers (or headers) to be wider than the margins used in the rest of your document? There ...

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 2 + 8?

2022-10-13 03:45:11

Saddam

I,ve been using your macro, it worked most of the times. However I have a problem when I need to appear bullet and numbering along with two-word footer, it can't be done. Hopefully you could give me the solution. Best regards.
Saddam from Indonesia.


2017-02-07 14:54:02

Anita Duvall

@ Jack Sons

Use the Different Odd & Even Pages option in the Header and Footer Design tools. This will allow you to create a footer for the odd pages with the z.o.z. text. You would create a different footer for the even pages without the extra text.


2017-01-28 07:38:29

Jack Sons

I used this sub (placed in a module in Normal.dot) on a two page document (paragraphs without numbering).
The sub places the first two words of page 2 in the footer of page 2 in stead of the footer of page one.
What went wrong and how can I correct it?

Other question:
If a document is printed on both sides of the sheets I want
1) automatic pagenumbering
2) at the right hand side of the footer of all uneven numbered pages (1, 3 etc.) the string "z.o.z."(without the ")because in my language (Dutch)it is the abbreviation for "see other side".

Thans in advance for your help.

Jack Sons (reader of your tips for at least the last 20 years)
The Hague
The Netherlands
using Word 2010 W7


2017-01-28 06:32:54

Alfred J. Lemire

No tip, just a question: Does Word provide, or does it presently allow as a option, tighter interlinear spacing?

Starting with the 2007 version, 2008 o the Mac, Ms Word increased the space from one baseline of text to the other. That made correspondence look unnatural and lessened he amount of text one can save on a page.

I gave up with the 2011 version, 2010 on a PC. Word still disallowed tight lines and the looser ones are unusable. I found a way to get around the problem by saving all text as .doc files. I lead Often-used files with a dummy .doc document, which I call backup.doc—could be any wording before .doc, of course. Then I choose 'Save as," and type in the file name. That puts the news file into Often-used files. Later, I open Often-used and move files to the folders where they should go.

Actually, I have no idea how I would get files into folders if I could just open a document and type away, without the special Save as routine.

Also, at some point, I think I was given a tip that let me get into some Word file that let me set certain typefaces, or fonts, as standards. One must have been Palatino, a typeface I now abhor, set at 14 points. I use Verdana at 12 point when I save URLs, and occasionally Word changes that to Palatino at 14 points. Usually, I catch the change and reset the preferred 12-pt Verdana. Body text is usually 15-pt Lucida Bright.

Sometimes, dipping into old, long files, which contain groups of files, mostly downloaded from various websites, I find that all my formatting has been changed. Type colors, like red for dates, are lost, Verdana headline sizes are changed, and usual 15-pt Lucida Bright text has become changed to 14-pt Palatino. The result is hard for my older eyes to read. With some of the files containing hundreds of pages, getting rid of the changes takes up too much time.

Going to Font under Format does not solve the problem. I have tried, but failed, to remove Palatino from my list of available typefaces, or fonts.

Most annoying.

But also, I doubt that Ms Word lets one set Hanging indents at 2 picas, which I prefer to the Word-specified standard of 3 picas. I have no incentive to update my version of Word. I do not know the features of Word 2013 for the PC, likely 2014 for my Mac, anyway, since I have never seen any publicity for the most recent upgrade.

Thank you.


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.