|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
可结合书签进行设置,在每节起始位置插入一个书签,书签命名规则为“sec"+节编号,如sec1,则页脚含域代码的文本为: 第 {={ page }-{ pageref "sec{ section }" }+1 } 页,共 {sectionpages } 页。总第 { page } 页,共 {numpages } 页。宏代码:
- Sub test()
- '同时显示节内页码和文档总页码
- Dim i%, n%, achar, codetext
- Dim aSec As Section
-
- achar = Array(15, 11, 6, 2)
- codetext = Array("numpages", "page", "sectionpages", "=page-pageref ""secsection""+1")
- For Each aSec In ActiveDocument.Sections
- i = i + 1
- With aSec.Range '每节开头插入一个指定名称的书签
- .Collapse wdCollapseStart
- ActiveDocument.Bookmarks.Add "sec" & i, .Duplicate
- End With
-
- If aSec.Footers(wdHeaderFooterPrimary).LinkToPrevious = False Then '如果指定页脚与前一节不同
- With aSec.Footers(wdHeaderFooterPrimary).Range
- .Text = "第x页,共y页。总第m页,共n页"
- For n = 0 To 3
- .Fields.Add .Characters(achar(n)), , codetext(n), False
- Next
- With .Fields(1).Code
- .SetRange .Start + 7, .Start + Len(.Text) - 3
- .Fields.Add .Duplicate, , .Text, False
- .SetRange .Start - 5, .Start + Len(.Text) - 1
- .Fields.Add .Duplicate, , .Text, False
- End With
- With .Fields(3).Code
- .SetRange .Start + 13, .Start + Len(.Text) - 2
- .Fields.Add .Duplicate, , .Text, False
- End With
- .ParagraphFormat.Alignment = wdAlignParagraphCenter
- End With
- End If
- Next
- End Sub
复制代码
|
|