Update Page Numbers

D

Derek Hart

I am running the following code to try to update and unlink page number
fields. Very inconsistent results are happening. Sometimes it works;
sometimes it updates all the page numbers to 1; sometimes it updates all the
page numbers to 1 except the last page number is correct. What is the right
way to do this? I want to unlink the field and save the file.

Dim oSec As Section
For Each oSec In ActiveDocument.Sections
oSec.Range.Collapse wdCollapseEnd
With oSec.Range.Fields
.Update
.Unlink
End With
With oSec.Headers(wdHeaderFooterPrimary).Range.Fields
oSec.Range.Collapse wdCollapseEnd
.Update
.Unlink
End With
With oSec.Footers(wdHeaderFooterPrimary).Range.Fields
oSec.Range.Collapse wdCollapseEnd
.Update
.Unlink
End With
Next

Derek
 
S

Stefan Blom

I don't see how you could unlink page numbers (and keep them all
different, that is, reflecting the actual page number) unless each page
is in a separate section (whose headers and footers are unlinked).

What are you trying to accomplish? Note that if you are trying to
prevent layout changes, it will be easier to create a PDF instead.

--
Stefan Blom
Microsoft Word MVP


in message
news:[email protected]...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top