PageNum and NumPages

D

Derek Hart

I am building complex documents that need Page X of Y in the footer, and
this is happening all in VBA. I am combining documents in code, and cannot
have the pagenum and numpages fields linked when the document is completed,
because it is combined with other documents. So I will get a final document
and need to write my own page numbers in the footer. Every page will be in
its own section and linktoprevious will always be false. I do not see a
Pages collection to loop through. Does anybody have a sample of how I might
do this? Use bookmarks perhaps? I just want to loop from page to page and
fill in the bookmark with Page X of Y. Please help!

Derek
 
J

Jay Freedman

Since every page is its own section, loop through the document's Sections
collection. Something like this:

Sub demo()
Dim oSec As Section
Dim SecNum As Long
Dim SecCount As Long

SecCount = ActiveDocument.Sections.Count

For SecNum = 1 To SecCount
Set oSec = ActiveDocument.Sections(SecNum)
oSec.Footers(wdHeaderFooterPrimary).Range.Text _
= "Page " & SecNum & " of " & SecCount
Next
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
D

Derek Hart

I might have more sections than just one per page... lots of columns... how
can I do this per page?

Derek
 
J

Jay Freedman

Why can't your macro just stick an ordinary Page {PAGE} of {NUMPAGES}
in the footer of the combined document? There's no reason the fields
should need to link back to the source documents.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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