17

I'm trying to use the following as a field in word:

{ = { NumPages } - 1 }

And I get the following error:

!Syntax Error, {

I seem to be using the right format per Microsoft. Any ideas? Thanks as always.

Mark Williams
  • 588
  • 6
  • 10
  • 17

3 Answers3

27

The following are the steps that you will have to follow to do what you are after:

  1. Press Alt+F9 to reveal the field codes.
  2. Select the whole of the {NUMPAGES} field including the { and }
  3. Press Ctrl+F9 - this will place a pair of braces { } around the NUMPAGES field so that it now looks like:

    { {NUMPAGES} }
    
  4. Between the { {, insert an = sign, and between the } } insert -1 so that the field now looks like:

    {={NUMPAGES}-1}
    
  5. Now press Alt+F9 to hide the field codes and select the field, which will still probably shown the total number of pages and press F9 to update the fields. You should now have the result that you are after.

Previewing the document will also update the fields as will printing it if the Update Fields box is checked under the Tools>Options>Print menu item (newer versions will put it in File>Options>Display).

enter image description here

The main thing to remember when working with fields is that you must use Ctrl+F9 to insert a pair of { }. Typing them in from the keyboard does not work.

krowe
  • 5,629
4

For those who can't get it right using Mark's advice: I have a Word 2010 and for me the trick is to add each pair of braces using Ctrl+F9. Don't type {NUMPAGES}. Type NUMPAGES, select it and press Ctrl+F9 instead.

2

@Vladipolis, what you wrote is THE key to this whole strange operation. I could not get math involving page references to work until I followed your instructions. In short, each field needs to be an independent "object", or it won't work.

In my case, I wanted to get the count of pages, excluding the number of pages in the section.

This does not work (even though it would be a lot easier if it did!):

  1. Type = { NUMPAGES } - { SECTIONPAGES }
  2. Select that entire block of text and press Ctrl+F9(this will actually fail to turn it into a proper field even though it might look like it worked)

This does work:

  1. Press Alt+F9 to reveal field codes
  2. Type NUMPAGES
  3. Select NUMPAGES and press Ctrl+F9 to turn it into a proper field
  4. Type SECTIONPAGES to the right of the { NUMPAGES } field
  5. Select SECTIONPAGES and press Ctrl+F9 to turn it into a proper field
  6. Type = to the left of the { NUMPAGES } field
  7. Type - between the { NUMPAGES } and { SECTIONPAGES } fields
  8. Select = { NUMPAGES } - { SECTIONPAGES } and press Ctrl+F9 to turn the whole thing into a proper field (of nested fields!)
John T.
  • 341