Inserting page numbering with a macro in the document style

WP X8 version, Win 10 Pro.

I have been unable to figure out how to insert page numbering into the document style using a macro. Perhaps I've missed something that should be obvious.

I run the macro to create a new document, and want to insert a variable title (fixed thereafter for the document) into the page number. The macro does much more than that (including generating and validating the variable part of the page number format), but for this problem the rest is irrelevant.

e.g. I want something like "Document 1, Page "[Page #]    Where [Page #] represents the WP code for "insert the page number here", as it appears if you set up page numbering via the dialog.

   vTitle := "Document 1, Page "

   PageNumberFormat (vTitle)

gets me part way there. But I cannot figure out how to insert the [Page #] code.

PageNumberDisplay() does not do it. It just types out the page number wherever the current justification, etc. puts it. It is very different from the proper PageNumberFormat as the dialog would generate. PageNumberDisplay(), for example, does not respond to Suppress (Item:PageNumbering!).

Sample code:

//Application (WordPerfect; "WordPerfect"; Default!; "EN")

vTitle := "Document 1, Page "

PosDocVeryTop ()
StyleEditBegin (Style:DocStyle!; Library:CurrentDoc!)
StyleCodes (State: WithOffCodes!; Library: CurrentDoc!)
PageNumberPosition (TopRight!; DontUseDefaultValues!; "Dark Courier"; 12p)
PageNumberFormat (vTitle)
Suppress (Item:PageNumbering!)
HeaderA (Create!; Occurrence:AllPages!; Margin:On!)
Advance (Where:AdvanceFromTop!; "0.64i" )
SubstructureExit ()
SubstructureExit ()
StyleEditEnd (State: Save!)


The following 2 screen scrapes show the results on the first 2 pages of the document. 

Before the macro (above) ran, page 1 contained 2 lines:

text stuff
more text stuff

and page 2 contained 1 line:

even more stuff

Note the "1" (the page number) inserted before "text stuff".

The actual page number format (top right) is correctly suppressed.

The "2" in the upper left corner appears on all 3 pages. The PageNumberDisplay() generates it. PageNumberDisplay() is not supposed to be a function and cannot be called as a function.

Commenting out the PageNumberFormat (vTitle) and PageNumberDisplay() generates the actual page numbers correctly, but without the desired formatting.

I suspect I would have exactly the same problem (not able to get the page # into the page number format), if I tried to insert the page numbering into HeaderA.

Thanks in advance for any assistance.

- Steve

  • This may not be what you want, but rather than using styles, I use the original page numbering techniques.  The following macro appears to do what you want:

    Application (WordPerfect; "WordPerfect"; Default!; "EN")

    vTitle := "Document 1, Page "

    PageNumberFormat (Format: vTitle + "[Macro Func: Page #]")

    PageNumberPosition (Position: TopCenter!; Default: DontUseDefaultValues!)


    The item marked in red is a code that can be inserted from the macro toolbar.  It was automatically inserted when I simply recorded the steps using Format > Page > Numbering > Custom Format, and then altered the resulting macro to extract the vTitle variable.