![]() |
|
#1
|
|||
|
|||
![]() Something like this: Code:
Sub CreatePageRefs() Application.ScreenUpdating = False Dim rng As Word.Range, Sec As Word.Section, ft As Word.HeaderFooter, i As Long Set Sec = ActiveDocument.Sections(1) 'The first section, in Roman (i, ii, iii) Set ft = Sec.Footers(wdHeaderFooterPrimary) Set rng = ft.Range With ft.PageNumbers .NumberStyle = wdPageNumberStyleLowercaseRoman .RestartNumberingAtSection = True .StartingNumber = 1 .ShowFirstPageNumber = False End With 'rng.Style = wdStyleFooter rng.ParagraphFormat.Alignment = wdAlignParagraphCenter rng.Collapse wdCollapseEnd 'rng.Fields.Add Range:=rng, Type:=wdFieldPage Set Sec = ActiveDocument.Sections(2) 'The second section, 'switch to Arabic numbering (1,2,3) Set ft = Sec.Footers(wdHeaderFooterPrimary) Set rng = ft.Range ft.LinkToPrevious = False With ft.PageNumbers .NumberStyle = wdPageNumberStyleArabic .RestartNumberingAtSection = True .StartingNumber = 1 .ShowFirstPageNumber = False End With Dim numOfSections As Integer numOfSections = ActiveDocument.Sections.Count For i = 3 To numOfSections 'All remaining sections ' -- restart so that first page number set to "False" Set Sec = ActiveDocument.Sections(i) Set ft = Sec.Footers(wdHeaderFooterPrimary) ft.LinkToPrevious = False Set rng = ft.Range With ft.PageNumbers .NumberStyle = wdPageNumberStyleArabic .RestartNumberingAtSection = True .StartingNumber = 1 .ShowFirstPageNumber = False End With Next End Sub |
#2
|
|||
|
|||
![]()
I have substituted your
Code:
.RestartNumberingAtSection = True I am still unable to work out how to center the page number on the page (it currently sits in a frame on its own aligned to the right of the document), because Code:
rng.ParagraphFormat.Alignment = wdAlignParagraphCenter How do I center the page number frame in VBA? This is quite easy to do by right clicking, Format Frame > Position > Center, but I cannot replicate this programmatically. |
![]() |
Tags |
field codes, headers and footers, page numbers |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
SDwriter | Word | 12 | 10-25-2017 06:56 AM |
![]() |
Jashley1 | Word | 2 | 11-25-2014 10:36 PM |
![]() |
onemorecupofcoffee | Word | 18 | 09-04-2013 04:31 PM |
![]() |
panel | PowerPoint | 1 | 08-16-2012 06:33 AM |
Page Header and Page Numbering for Technical Book | SQLUSA | Word | 4 | 06-25-2012 09:53 AM |