下面代码的功能是,通过VBA设置word页脚为“第X页 共Y页”,同时,对齐方式为居中。
With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary)
Set rng = .Range
rng.Text = "第 "
rng.Collapse wdCollapseEnd
ActiveDocument.Fields.Add rng, wdFieldPage, "Page"
Set rng = .Range
rng.Collapse wdCollapseEnd
rng.Text = " 页 / 共 "
rng.Collapse wdCollapseEnd
ActiveDocument.Fields.Add rng, wdFieldNumPages, "Pages"
Set rng = .Range
rng.Collapse wdCollapseEnd
rng.Text = " 页 "
.Range.Fields.Update
.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
End With