Mega Code Archive

 
Categories / VisualBasic Script / Word
 

Creating Page X of Y Page Numbers

Sub pageNumber()     ActiveDocument.Sections(ActiveDocument.Sections.Count) _         .Headers(wdHeaderFooterPrimary).Range.Select     With Selection         .Paragraphs(1).Alignment = wdAlignParagraphCenter         .TypeText Text:="Page "         .Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _             "PAGE ", PreserveFormatting:=True         .TypeText Text:=" of "         .Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _             "NUMPAGES ", PreserveFormatting:=True     End With End Sub