Page numbering and formatting

C

Caroline

Can anybody help?

I am currently updating a document template using VBA. Unfortunately,
I am relatively new to VBA and have found myself running into a brick
wall.

The document will have 3 parts: preface, main body and appendices.
Each part must use the 'Page x of y' format. The problem is the main
body and appendices may have multiple sections; therefore,
wdFieldNumPages and wdFieldSectionPages do not work for the 'y'
property, as one obviously counts all of the pages in the document and
the other only counts the pages of a single section.

I am currently using the following code:

Dim iSec As Integer
Dim rngHeader As Range

iSec = ActiveDocument.Sections.Count
Set rngHeader = ActiveDocument.Sections(iSec).Head(wdHeaderFooterPrimary).Range
With rngHeader
.Text = "Page"
.Collapse wdCollapseEnd
.Move unit:=wdCharacter, Count:=1
.Fields.Add Range:=rngHeader, Type:=wdFieldPage
.Collapse wdCollapseEnd
.Move unit:=wdCharacter, Count:=1
.Text = "of"
.Collapse wdCollapseEnd
.Move unit:=wdCharacter, Count:=1
.Fields.Add Range:=rngHeader, Type:=wdFieldNumPages
End With

I have no idea how I might adjust this code to make the 'y' property
display the correct number of pages. If anyone can shed any light on
this problem it would be greatly appreciated.

Thanks in advance
Caroline
 
W

Word Heretic

G'day (e-mail address removed) (Caroline),

Cycle through each relevant section, adding up the total number of
pages, then revist them all to add the figure in.

Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


Caroline reckoned:
 

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