We have large documents that use legal numbering (1, 1.1, 1.1.1) for main content and alphabetic letters for appendices (e.g. Appendix A, B, C, etc.), and we re-start numbering for each appendix. We set up a separate list style for the appendices with lettered numbering, so that much is fine. The problem is that when page numbers appear in the Table of Contents and Figures, people looking at printed copies don’t which page 1 to go to, so we tried adding ‘chapter’ numbers before the page numbers. That was the only way we found to display them in the TofC. But the chapter numbers Word adds are always formatted as Arabic numerals (1-1, 2-1 instead of A-1, B-1). (The Insert Page Number dialog in Word lets you format the page number, but not the chapter number for some reason.) So I’m hoping there is a way to do that using VBA.
The documentation for the PageNumbers object seems to indicate it can be done, since it says you have to apply a list template before you can include chapter numbers. (Wouldn’t Word use the numbering scheme from the template?), but I haven’t been able to figure out how to do it.
I tried running the sample code (See Sub SetChapterPageNumbers below), and it didn’t work. (It displayed the chapter number + 1, not the chapter number (‘Chapter 1’, pg. 1 displayed as ‘2-1’), and since the list style used Arabic numbers for the chapter, it didn’t tell me whether the list numbering format was used. Apart from that, it appeared to set a ListFormat for the entire document and we just want to apply it to the appendices. When I tried to apply a ListFormat for just the first appendix, using the sample as a model, all it did was set all the content in that section to the Appendix Heading Level 1 style:
Set wdDoc = ActiveDocument
wdDoc.Sections(5).Range.ListFormat.ApplyListTemplate ListTemplate:=wdDoc.Styles("Appendices").ListTemplate
Sub SetChapterPageNumbers()
'copied from Microsoft PageNumbers.HeadingLevelFormat example
'The first part of this example creates a new document, adds chapter titles and page breaks, and then formats the document by using the last numbered outline format listed in the Bullets and Numbering dialog box.
'The second part of the example adds centered page numbers - including the chapter number - to the header; an en dash separates the chapter number and the page number. The first heading level is used for the chapter number, and lowercase roman numerals are used for the page number.
Dim intLoop As Integer
Dim hdrTemp As HeaderFooter
Documents.Add
For intLoop = 1 To 5
With Selection
.TypeParagraph
.InsertBreak
End With
Next intLoop
ActiveDocument.Content.Style = wdStyleHeading1
ActiveDocument.Content.ListFormat.ApplyListTemplate _
ListTemplate:=ListGalleries(wdOutlineNumberGallery) _
.ListTemplates(7)
Set hdrTemp = ActiveDocument.Sections(1) _
.Headers(wdHeaderFooterPrimary)
With hdrTemp.PageNumbers
.Add PageNumberAlignment:=wdAlignPageNumberCenter
.NumberStyle = wdPageNumberStyleArabic
.IncludeChapterNumber = True
.HeadingLevelForChapter = 0
.ChapterPageSeparator = wdSeparatorEnDash
End With
End Sub