![]() |
|
|
|
#1
|
||||
|
||||
|
Frankly I wouldn't bother with inserting a building block by macro, or rely on the recorder, but to achieve the same result with a macro, try the following: Code:
Sub InsertPageNumInHeader()
Dim oRng As Range
Set oRng = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
With oRng
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Text = "[]"
.Collapse 1
oRng.Start = oRng.Start + 1
.Fields.Add oRng, wdFieldPage, "", False
End With
Set oRng = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#2
|
|||
|
|||
|
Thanks for that. I want to insert the page number in a footer, so I changed .Headers to .Footers and it worked fine.
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Numbering Page in Center of Page in Word | AdmirableWizard | Word | 3 | 04-26-2022 10:55 AM |
| Word 2019 & Page Numbering | PapaTom | Word | 18 | 12-13-2019 08:02 AM |
Word 10 Page Numbering
|
DarenKF | Word | 2 | 11-08-2017 01:43 AM |
Page-numbering question: continue numbering from one section to the next? {PAGE} of {SECTIONPAGES}
|
SDwriter | Word | 12 | 10-25-2017 06:56 AM |
Page Numbering in Word
|
dickmill | Word | 10 | 01-11-2016 04:10 PM |