|
楼主 |
发表于 2021-1-8 12:45
|
显示全部楼层
- Sub SectionPageNumber_Better()
- Dim i&, j&, inum&, spage
- With ActiveDocument
- j = .Sections.Count
- For i = 1 To j
- With .Sections(i).Footers(wdHeaderFooterPrimary)
- .LinkToPrevious = True
- .PageNumbers.RestartNumberingAtSection = False
- .Range.Delete
- End With
- Next
- inum = 2
- Dim sr As String
- sr = InputBox("请输入页码起始页,默认为2" + Chr(13) + Chr(13), 2)
- spage = InputBox("请输入页码开始数,默认为1" + Chr(13) + Chr(13), 1)
- If sr = "" Then Exit Sub
- If sr <> "1" Then
- Selection.GoTo what:=wdGoToPage, which:=wdGoToNext, Name:=sr
- Selection.InsertBreak Type:=wdSectionBreakNextPage
- End If
- With .Sections(inum).Footers(wdHeaderFooterPrimary).PageNumbers
- .Parent.LinkToPrevious = False
- .NumberStyle = wdPageNumberStyleArabic
- ' .NumberStyle = wdPageNumberStyleNumberInDash '-1-
- .RestartNumberingAtSection = True
- .StartingNumber = spage
- .Add PageNumberAlignment:=wdAlignPageNumberCenter, FirstPage:=True
-
- 'Extra Format/Can delete!
- With .Parent.Range.Font
- .NameAscii = "Times New Roman"
- .Size = 36
- .Bold = True
- .ColorIndex = wdRed
- End With
- End With
- End With
- End Sub
复制代码 此代码经测试能够实现从指定页开始设置页码。
如下图:从第3也开始设置页码,页码起始数为8.这两个都可以自定义输入。
更复杂的word文档没有测试,仅供参考。
|
|