Software

Display page-dependent messages in a header or footer

Use Word field codes to display informational messages in headers and footers, depending on the current page.

Displaying page numbers, dates, and document names in a header or footer are common tasks. Sometimes, your needs are more complex. For instance, you might want to display the phrase continued to let readers know there's more to the document than the current page. You might think this task requires a complex macro, but the easiest way to fulfill this type of requirement is to use fields.

This trick relies on nesting three fields: { IF }, { PAGE }, and { NUMPAGES }. First, open the header or footer. In Word 2007 and 2010, just double-click the area to open it. In Word 2003, choose Header and Footer from the View menu. With the header open, enter the appropriate nested field, as follows:

  1. Position the insertion point in the header where you want the text to appear.
  2. Press [Ctrl]+[F9].
  3. Type if (case doesn't matter).
  4. Press [Ctrl]+[F9].
  5. Type page.
  6. Use the right arrow key to move to the right of the next }.
  7. Enter a lesser than sign (<): {if{ page }< }
  8. Press [Ctrl]+[F9].
  9. Enter numpages.
  10. Use the right arrow key to move to the right of the next }.
  11. Enter the text you want to display, enclosed in double quotation marks: {if{ page }< { numpages }"Continued…"}
  12. Select the entire nested field and press [Shift]+[F9]. If the current page isn't the last page, the text will appear in the header or footer, accordingly. When the current page is also the last page, the text doesn't appear.

You must press [Ctrl]+[F9] to insert the field brackets. You can't type them from the keyboard. Now that you know the basic technique, you can modify it to suit your needs.

About

Susan Sales Harkins is an IT consultant, specializing in desktop solutions. Previously, she was editor in chief for The Cobb Group, the world's largest publisher of technical journals.

3 comments
Mark W. Kaelin
Mark W. Kaelin

What other uses would this technique be good for? Do you have a real life example to share?

Jeff_Mason
Jeff_Mason

I have used this to compare today's date to an expiry date when generating letters. The expiry date was supplied as a custom property. The nesting allowed me to say "expires TODAY!" instead of "expires ". I will admit though that I'm not a fan of the technique as nested functions aren't the easiest things to read and can't be documented. I often write small macros to examine fields and/or properties and then set another property value. All this requires is a simple reference to that property in the Word doc. All my contract docs do this to provide "I agree" or "we agree" according to how many parties are involved. The VBA is easy to read and can be properly documented with comments.

Jeff_Mason
Jeff_Mason

Very odd. I had written "date" between greater than and less than signs after "expires" and it disappeared. ' probably assumed it was a tag!

Editor's Picks