Word Syntax Error in expanding Page {Page} of {PageNumb} Statement in Header

Bill Golden
Bill Golden used Ask the Experts™
Syntax Error in expanding Page {Page} of {PageNumb}.

Various literature suggests you can limit the PageNumb aspect of the above statement with

Page {Page} of {={PageNumb}-1}

All I get is a Syntax Error. This function is used when your document contains miscellaneous pages at the end that you do not intend to utilize in (in our case) a pdf file.

Sample file indicating Syntax Error is attached. Any thoughts?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Andrew LeniartIT Professional | Freelance Journalist | Looking for Opportunities
Distinguished Expert 2018

Hi Bill,

This Microsoft Add page number X of Y to a document  will give you all the info you need.

Basically, the syntax for what you want to do is as follows;

  1. On the first page, in the Header Area, type Page and press your space bar
  2. Now on the Insert Tab, click Quick Parts and then click Field
  3. Under "Field Names", select "Page" on the left-hand side and choose a Format on the right-hand side Ie: 1,2,3, ...
  4. Click OK
  5. Press your Space Bar and type of and then press your space bar again
  6. Back on the Insert Tab, click Quick Parts and then click Field again
  7. Under "Field Names", select "NumPages" on the left-hand side and choose the same Format on the right-hand side Ie: 1,2,3, ...
  8. Done.

Your pages will now be numbered automatically.

Let me know if you need additional help.

Regards, Andrew
The field code you need to use to display the total number of pages is NUMPAGES (i.e. not “PageNumb”).

To edit a field code, press Alt-F9 to toggle visibility between results and the field codes. You can then use normal Word editing to make changes. When finished, press Alt-F9 again and press F9 to recalculate the field to see the updated results.


The approach you are using will display “Page 11 of 38” for page 11 if the document is 38 pages plus one extra page. However, if a different document had four extra pages, you would need to change the calculation to { = {Numpages - 4 } } to display the last relevant page number.

As an alternative that would not require knowing how many extra pages are included, you could include a bookmark at the end of the relevant content and use the PAGEREF cross-reference field code to display the page number.Field codes and results showing how Pageref can be used
The calculation field code is included as an example to show how you could report that information as well if required. (I have seen this used for reporting the number of errata pages for procedure manuals.)

Note: In the screen shots above, the gray shading appears because I have turned on the option in File > Options > Advanced > Show document content, “Field shading = Always”. This causes all field codes and their results to be displayed in on-screen views with the background shading so you can easily tell whether content has been typed or is being calculated. The shading will not be printed. If you use field codes, this is a very useful option to have permanently turned on.

Here's a screen shot of the last “relevant” page in my test document to show how I bookmarked a decorative ending mark so it could be used in the Pageref field code. Note that the status bar is reporting “Page 8 of 12” because I had included 4 extra pages after this mark.
Using a decorative mark for an end of document bookmark
(Like the gray field code shading,the gray [ and ] non-printing marks around the bookmark are displayed so I can readily see where content is bookmarked. This option can also be permanently turned on via the “Show bookmarks” checkbox in the same Word Options dialog.)
Bill GoldenExecutive Managing Member


Andrew, thanks for the response. Unfortunately, the document does not address the problem.
Word 2016 inserts the field commands as follows


Which works identically to

Page { PAGE } of { NUMPAGES }
 (which the nomenclature used in some previous versions of Word.)

There is ample literature about inserting -1, -2, -3, etc. after the NUMPAGES command (but I was unable to find anything about positioning -1 immediately after NUMPAGES or after MERGEFORMAT.  

I have attached a sample file which contains a header line formatted with


So, I am still looking as to where to insert, in this case, the -1 operand.
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Bill GoldenExecutive Managing Member


Eric, thanks for the response. Unfortunately, your suggested solution does not work!

(I apologize for using the term PAGENUMB instead of NUMPAGES in the initial comment. The supplied example file did use the command NUMPAGES.
Actually, Word 2016 inserts the field commands as follows


Which works identically to

Page { PAGE } of { NUMPAGES }
 (which was the nomenclature used in some previous versions of Word.)

There are ample internet examples about inserting -1, -2, -3, etc. after the NUMPAGES command as per your suggestion. However, I was unable to find anything about positioning -1 when the command contained the operand \* MERGEFORMAT.  

I have attached a sample file which contains the following three different header lines at the top of Page 2 formatted as follows:

Page { PAGE } of { NUMPAGES }

and I even added a line that reads just...

{={NUMPAGES-1} }

The last line, when toggled, returns a Syntax Error

So, I am still looking as to where to insert the -1 operand.
I assumed you wanted it to report a number that is 1 less than the total number of pages in your document. To do that, you need to use the syntax in my earlier comment.

However, in looking at your document, I can see the problem. Your structure {={NUMPAGES-1}} won't work as entered because the Numpages field has the operator and value within it instead of as a part of the equation field code. If you choose to leave the Mergeformat switch in the field code, it would need to be like this:
(The spaces are typical of what Word adds, although they are not specifically required.)

Parsing it out as Word will do the calculation: { NUMPAGES } gets resolved first — in your document, as 3. The Mergeformat switch is ignored. The equation field code is then calculated as { = 3 - 1 } to give you 2 as the result.

If you use the UI to insert the field codes, the \* Mergeformat switch typically gets included by default (although you can turn the “Preserve formatting during updates” checkbox off to exclude it). But it and any other switches are part of the field code, and must be included within the automatic braces that Word inserts for you if you press Ctrl-F9 to manually type a field code. They are also included within the braces when you insert a field code with selected switches from the UI (Insert > Quick Parts > Field...).

Note that the equation field code can be handy if you need to do ad hoc math in Word: { = 765 / 19 } will display 40.26. However if you edit the field code to add a numeric picture switch, { = 765 / 19 \# "#,##0.0000" }, it will display as 40.2632. Here, the numeric picture switch is part of the equation field code.

To reinforce the importance of how switches can influence field code results in equations, consider this: { = { Page \* roman } + 3 }. Here, the number switch would cause the digits of the current page number to be resolved as "ii" (instead of 2) first, and you'd see an error. The error in this case would be "undefined bookmark" because the parser would see "ii" as text and try to interpret it as a bookmark. So unless you just happened to have a number set within a bookmark named "ii", the formula would fail.

Try entering the formula you need manually to get a better sense of how it works:
  1. Press Ctrl-F9 to have the cursor positioned between the field code braces
  2. Type = and a space
  3. Press Ctrl-F9 again to insert a new field code with the cursor between the braces
  4. Type Numpages
  5. Now press the right arrow three times to move beyond the } after Numpages
  6. Type -1 and a space
  7. Press F9 to calculate the formula

Remember that Alt-F9 will toggle between field code results and the editable field codes.
Bill GoldenExecutive Managing Member


Well, I tried but all I ending up getting was an "Undefined Bookmark." It is obviously beyond me. Maybe if I was not still dealing with the aftereffects of chemotherapy I could get it.

Anyway, I was told this morning just to float the file on one of the pay sites which seems ridiculous to fix a single problem. But the delay is holding up the mailout of a number of documents and several people working on the project are going to be furloughed out waiting on one stupid issue.  I will probably cost a couple of hundred dollars to find someone to fix the problem but obviously I cannot get it done.

I am going to take some solace in the fact that it is obviously more difficult than it seems since in supplying an exact example of the file multiple time, I have yet to receive a file that someone has actually made the syntax work!

Thanks for trying.  Bill
I hope you haven't already had to pay Bill. I've attached your file with the changes I suggested in the page header. Use Alt-F9 to toggle the view to see what I did.

BTW, at >3MB, this file seems awfully large for a 3-page letter. I think you could reduce it substantially by simplifying the formatting: for example, the block of names at the top of page 1 could be set with a centered and a right tab instead of using spaces to approximate the centered and right-aligned content. If you ended each line with Shift-Enter (instead of Enter), the whole block would be a single paragraph, so it would reduce Word's overhead for managing the formatting. SImilarly, using "space before" will eliminated the need for many of the multiple Enters.
Bill GoldenExecutive Managing Member


Thank you very much. I did get the download before outsourcing the problem and we are processing numerous documents, some with one, two or three pages of data beyond the basic document.

It appears I can just copy the line at will modifying the number of pages. This will, of course, be very helpful. While I have drafts that "look" exactly like what you sent, it is painfully obvious that the line must be created in a precise manner in order to work.

Thanks again for your help,

Bill GoldenExecutive Managing Member


I greatly appreciate all the help.

Yes, field codes do have pretty specific structures.

If this is something you need frequently Bill, consider adding it as an AutoText entry so you don't need to create it each time. Create it once (and test it), then select it and use Insert > Quick Parts > AutoText, and choose the bottom option to "Save selection to AutoText Gallery". In the resulting dialog, give it a meaningful name (no spaces or punctuation); add a meaningful description so you'll know what it is later; make sure it is saving the item in your Normal template (the default); then click OK.Creating an AutoText entry to be able to insert a field code equation
Now when you need the formula, just start typing the name. As you type, a pop-up will appear when enough unique letters are entered to enable Word to guess what you want, and you can press Enter to complete the AutoText. For the above example, the popup appeared when I pressed the "l". (This is why it is a good idea to use a name that won't be confused with a normal word.) Alternatively, you can type the AutoText name and press F3 to add the content to your document.

An AutoText entry can include multiple lines or paragraphs, so your entire header block could be included in one. The screen shot below shows the result of my AutoText entry named “ltrhdr”. It uses StyleRef field codes to automatically insert whatever has been set with the “addressee name“ style, then a line with the page number info, followed by another StyleRef to insert the date of the letter (which is tagged by my “date” style). The picture on the right shows how it will appear in the upper right header position of all but the first page of any letter.Example of a multi-line AutoText using field codes
(In fact, this structure is included in my personal letter template, so any letter I create from that template will already have everything set up (including today's date already set with my “date” style and with the cursor on an empty line already tagged with the “addressee name” style). All I need to do is type in the content.)

In your sample document, the large block of names on page 1 could be defined in an AutoText entry. That way, it would simplify entering it when needed, but also, could be modified (edited & resaved) if one of the names or titles changed. When saved in the default Normal template, any such AutoText entries will be available to any document.

Although they may be a pain to deal with initially, field codes can be extremely useful in automating repetitive tasks and making use of content already available. Well worth the effort to learn in my humble opinion!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial