|
以下代码借鉴高人,也添加点内容,文章有2节,可不管怎么样都要运行2次代码,才是从第2节开始插入页码。运行第1次是给第1节插入页码。
- Sub 页码()
- Dim wdApp As New Word.Application, wdDoc As Word.Document
- Set wdDoc = ActiveDocument
-
- Dim r As Range
- '给文档的第二节页脚添加页码
- Set r = wdDoc.Sections(2).Footers(wdHeaderFooterPrimary).Range
- wdDoc.Sections(2).Footers(wdHeaderFooterPrimary).LinkToPrevious = False
- With r
- .InsertAfter "-"
- .Font.Size = 10.5
- .Collapse Direction:=wdCollapseEnd
- '插入页码域
- .Fields.Add Range:=r, Type:=wdFieldEmpty, Text:= _
- "PAGE \* Arabic ", PreserveFormatting:=True
- .Expand Unit:=wdWord
- .InsertAfter "- "
- .ParagraphFormat.Alignment = wdAlignParagraphCenter 'wdAlignParagraphRight
- End With
- '隐藏页眉的横线
- wdDoc.Sections(2).Headers(wdHeaderFooterPrimary).Range.Borders(wdBorderBottom).Visible = False
- With wdDoc.Sections(2).Footers(wdHeaderFooterPrimary).PageNumbers
- .NumberStyle = wdPageNumberStyleArabic
- .HeadingLevelForChapter = 0
- .IncludeChapterNumber = False
- .ChapterPageSeparator = wdSeparatorHyphen
- .RestartNumberingAtSection = True
- .StartingNumber = 1
- End With
- End Sub
复制代码 请论坛高手指点。
|
|