J
JonSteng
MS XP / Word 2000 – 2003
Page Numbering Woes – I am having a hard time getting my document to
correctly number pages, any help greatly appreciated.
I am working on a macro that allows users to apply formatting to a document,
add table of contents and insert other documents (called boilerplates) to the
beginning of the original (after TOC).
I am able to insert the requested documents using the following code:
Note: at the time of inserting the documents the table of contents has
already been inserted.
Sub _Boilerplates()
'add selected boilerplates to current document
Dim iCnt As Integer
For iCnt = 0 To frmSpecMain.lbBoilerplates.ListCount - 1
If frmSpecMain.lbBoilerplates.Selected(iCnt) Then
Selection.HomeKey Unit:=wdStory
ActiveWindow.ActivePane.View.Type = wdPageView
' Go to second section
Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=2, Name:=""
Selection.InsertFile FileName:=gstrDocFullPath & _
frmSpecMain.lbBoilerplates.List(iCnt), _
Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False
Selection.InsertBreak Type:=wdSectionBreakContinuous
End If
Next
ActiveDocument.Save
End Sub
After inserting the boilerplates I run the following code to number the pages:
Sub _PageNumbers()
'
' Add page numbers to the final document
'
Dim i As Integer
i = Selection.Sections.Count
' go to top of document and clear find area
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.HomeKey Unit:=wdStory
With Selection.Sections(1).Headers(1).PageNumbers
.NumberStyle = wdPageNumberStyleLowercaseRoman
.HeadingLevelForChapter = 0
.IncludeChapterNumber = False
.ChapterPageSeparator = wdSeparatorHyphen
.RestartNumberingAtSection = True
.StartingNumber = 1
End With
Selection.Sections(1).Footers(1).PageNumbers.Add PageNumberAlignment:= _
wdAlignPageNumberRight, FirstPage:=True
For i = 1 To Selection.Sections.Count + 1
' Skip to Next Section and number those pages
Selection.GoTo What:=wdGoToSection, Which:=wdGoToNext, Count:=1, Name:=""
Selection.Sections(1).Footers(1).LinkToPrevious = False
' Now number body
With Selection.Sections(1).Headers(1).PageNumbers
.NumberStyle = wdPageNumberStyleArabic
.HeadingLevelForChapter = 0
.IncludeChapterNumber = False
.ChapterPageSeparator = wdSeparatorHyphen
.RestartNumberingAtSection = True
.StartingNumber = i - 1
End With
Selection.Sections(1).Footers(1).PageNumbers.Add PageNumberAlignment:= _
wdAlignPageNumberRight, FirstPage:=True
Next
End Sub
What happens is that the newly inserted boilerplates all have the page
number 1, as well as the beginning of the original document.
Harrumph.
Again any suggestions greatly appreciated, thank you all from Sunny Central
Florida.
Page Numbering Woes – I am having a hard time getting my document to
correctly number pages, any help greatly appreciated.
I am working on a macro that allows users to apply formatting to a document,
add table of contents and insert other documents (called boilerplates) to the
beginning of the original (after TOC).
I am able to insert the requested documents using the following code:
Note: at the time of inserting the documents the table of contents has
already been inserted.
Sub _Boilerplates()
'add selected boilerplates to current document
Dim iCnt As Integer
For iCnt = 0 To frmSpecMain.lbBoilerplates.ListCount - 1
If frmSpecMain.lbBoilerplates.Selected(iCnt) Then
Selection.HomeKey Unit:=wdStory
ActiveWindow.ActivePane.View.Type = wdPageView
' Go to second section
Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=2, Name:=""
Selection.InsertFile FileName:=gstrDocFullPath & _
frmSpecMain.lbBoilerplates.List(iCnt), _
Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False
Selection.InsertBreak Type:=wdSectionBreakContinuous
End If
Next
ActiveDocument.Save
End Sub
After inserting the boilerplates I run the following code to number the pages:
Sub _PageNumbers()
'
' Add page numbers to the final document
'
Dim i As Integer
i = Selection.Sections.Count
' go to top of document and clear find area
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.HomeKey Unit:=wdStory
With Selection.Sections(1).Headers(1).PageNumbers
.NumberStyle = wdPageNumberStyleLowercaseRoman
.HeadingLevelForChapter = 0
.IncludeChapterNumber = False
.ChapterPageSeparator = wdSeparatorHyphen
.RestartNumberingAtSection = True
.StartingNumber = 1
End With
Selection.Sections(1).Footers(1).PageNumbers.Add PageNumberAlignment:= _
wdAlignPageNumberRight, FirstPage:=True
For i = 1 To Selection.Sections.Count + 1
' Skip to Next Section and number those pages
Selection.GoTo What:=wdGoToSection, Which:=wdGoToNext, Count:=1, Name:=""
Selection.Sections(1).Footers(1).LinkToPrevious = False
' Now number body
With Selection.Sections(1).Headers(1).PageNumbers
.NumberStyle = wdPageNumberStyleArabic
.HeadingLevelForChapter = 0
.IncludeChapterNumber = False
.ChapterPageSeparator = wdSeparatorHyphen
.RestartNumberingAtSection = True
.StartingNumber = i - 1
End With
Selection.Sections(1).Footers(1).PageNumbers.Add PageNumberAlignment:= _
wdAlignPageNumberRight, FirstPage:=True
Next
End Sub
What happens is that the newly inserted boilerplates all have the page
number 1, as well as the beginning of the original document.
Harrumph.
Again any suggestions greatly appreciated, thank you all from Sunny Central
Florida.