Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2007

Tip: Looking for answers? Try searching our database.

PageNum and NumPages

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Derek Hart - 26 Jun 2007 17:15 GMT
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
Jay Freedman - 26 Jun 2007 21:21 GMT
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

Signature

Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

> 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,
[quoted text clipped - 7 lines]
> fill in the bookmark with Page X of Y.  Please help!
> Derek
Derek Hart - 26 Jun 2007 21:55 GMT
I might have more sections than just one per page... lots of columns... how
can I do this per page?

Derek

> Since every page is its own section, loop through the document's Sections
> collection. Something like this:
[quoted text clipped - 24 lines]
>> fill in the bookmark with Page X of Y.  Please help!
>> Derek
Jay Freedman - 27 Jun 2007 01:53 GMT
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        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

>I might have more sections than just one per page... lots of columns... how
>can I do this per page?
[quoted text clipped - 29 lines]
>>> fill in the bookmark with Page X of Y.  Please help!
>>> Derek
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.