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
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