pageref woes

Skip to first unread message


Aug 28, 2006, 7:29:03 PM8/28/06
I am using word 2000 with sp 3. In my document I have to create a weird
TOC: the "chapter names" entries are to be in blue but leader dots and
page numbers in black. The only way I figured out how to do that is to
bookmark the chaptes and construct each "TOC entry" as hyperlink to
the chapter bookmarks + pageref field to the bookmark.
On top of this, I have a VBA macro users need to run to accomplish
other tasks (include files, break links to the included files etc). I
made sure that bookmarks are NOT in included files but in the main
document. This macro also updates fields to show correct page numbers
in TOC - or is supposed to - and here is the problem:

Not all pageref fields in TOC get updated. BTW the pageref are wrong
on screen, but the links work properly...clicking on pageref brings me
to the correct place in the document

If I manually "select all" and press F9 repeteadly several times,
eventually all fields get updated.

So here is the first problem, as the whole process needs to be
automated, I need to be able to implement updating fileds in VBA macro.
I even tried puting Timer in VBA, waiting 10 secnds and updating fields
again, doing this several times, but no cigar.

Also, if I update fieldd manually (so they are all OK) and then switch
to print preview (and back), the pageref fields revert back to
original dummy values. (and yes, option update fields on print is

Does anyone have a clue why is this happening? Anyone else have seen
something like this? Other articles in this group suggest that PAGEREF
is supposed to work better than sectionpages field or numpages fields,
but for me it seems to be opposite...

Any help will be appreciated



Aug 28, 2006, 10:36:56 PM8/28/06
Partially answering my own question:

selection.EndKey unit:=wdstory
selection.HomeKey unit:=wdstory

with this piece of code, all fields are updated properly. Also works when
manually going to the end of document and then to the top, and updating all
fields- no more multiple updates needed. PrintPreview still messes them up

"iza" <dono...@postoffice.not> wrote in message

John McGhie [MVP - Word and Word Macintosh]

Aug 31, 2006, 7:55:38 AM8/31/06
Hi iza:

You've found it. The problem is that by the time you come to update the
fields, the document has not completed pagination.

Your macro is as good a way as any of forcing it to do that: it has to
resolve the pagination in order to find the "end".

You could try:

With ActiveDocument
End With

Which is a slightly more elegant way of doing the same thing, but I don;t
trust it. I am not sure that Word will correctly wait for the completion of
the Repaginate before running the fields.update.

However, if it does, ActiveDocument.Fields.Update updates all of the fields
in the document in a single command without any silly prompting as to what
you want to do :-)


On 29/8/06 12:36 PM, in article
bLNIg.659272$, "iza"
<dono...@postoffice.not> wrote:


Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 (0) 4 1209 1410


Aug 31, 2006, 2:20:41 PM8/31/06
thank you very much - I will try your suggestion.
You woudl not have a clue why print preview messes the pageref numbers
and seq fields ?...


John McGhie [MVP - Word and Word Macintosh]

Sep 2, 2006, 9:40:44 AM9/2/06
Yep. Print Preview sends the document to the "Printer" then intercepts the
result and displays that on the screen (effectively, it tells the printer
driver that the screen is a sheet of paper...)

This will force an update of all fields and a repagination. These are
required to draw an accurate Print Preview.

And if there's anything wrong with your field updating, you will see it...


On 1/9/06 4:20 AM, in article, "ip"


Sep 6, 2006, 10:59:21 AM9/6/06
Thanks John, This is how I understood Print Preview works.
The puzzle is, after updating fields (either manually or from macro)
and then switchign to print preview, the fields revert back to
un-updated state :-((

John McGhie [MVP - Word and Word Macintosh]

Sep 8, 2006, 6:07:17 AM9/8/06
Which fields are we talking about? (What's the field code...)?

I'm not understanding your situation. Every time you go into Print Preview,
hot fields will update. Warm fields will update if you have "Update fields"
set in your Print options. Cold fields will update only if you update them.

Hot fields are those that update continuously: PAGE fields are an example.
Warm fields are those that are updated on document open: DATE fields are an
example. Cold fields are those that must be updated manually: SEQ fields
are an example.


On 7/9/06 12:59 AM, in article, "ip"

Aug 28, 2016, 12:38:00 PM8/28/16
John, 10 years after this post, I wanted to say a big thanks. 2 hours of trying to understand why PageRef fields weren't updating led me nowhere (especially seeing that the code to update seemed perfectly fine, and worked perfectly well when run manually after all the rest of the code had run).

And then I stumbled upon this old thread, and it was the solution I was looking for. The trick was:

With ActiveDocument
End With

Thanks again!
Reply all
Reply to author
0 new messages