![]() |
#1
|
|||
|
|||
![]()
I recorded a macro to number pages. it includes:
Application.Templates( _ "C:\Users\gcpri\AppData\Roaming\Microsoft\Docu ment Building Blocks\1033\16\Built-In Building Blocks.dotx" _ ).BuildingBlockEntries("Brackets 1").Insert Where:=Selection.Range, _ RichText:=True When I run the macro it highlights the above in yellow and says: "Run-time error '5941'. The requested member of the collection does not exist." The cursor stops in the document in the footnote where the page number is to be inserted. I have recorded the macro several times and occasionally the VB Editor refers to the building blocks but it does not stay there when I record other macros. Allied to this is, when I record a macro can I allocate a project (or create a project) to contain the macro. The online help suggests that I have to go to the editor, start a new module and then cut and paste the code into that module. |
#2
|
||||
|
||||
![]()
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 |
#3
|
|||
|
|||
![]()
Thanks for that. I want to insert the page number in a footer, so I changed .Headers to .Footers and it worked fine.
|
![]() |
|
![]() |
||||
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 |
![]() |
DarenKF | Word | 2 | 11-08-2017 01:43 AM |
![]() |
SDwriter | Word | 12 | 10-25-2017 06:56 AM |
![]() |
dickmill | Word | 10 | 01-11-2016 04:10 PM |