|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
昨天看到论坛的分享贴,改写的代码。原链接是http://club.excelhome.net/thread-1572930-1-1.html
改写后实现1、页码是否奇偶页不同,2、是否顺延加页码的功能。
感觉代码有些繁琐,求论坛里精简。不会引用函数啊。
- Sub 分节页码()
- Dim i&, j&, k&, l&
-
- If MsgBox("是:奇偶页码相同(否:奇偶页码不同)?", 4 + 48) = vbYes Then l = 1
-
- If l = 1 Then
-
- If MsgBox("是:页码每节顺延(否:页码每节初始)?", 4 + 48) = vbNo Then k = 1
- With ActiveDocument
- j = .Sections.count
- '第1节:封面,无页码!
- With .Sections(1)
- .Footers(wdHeaderFooterPrimary).Range.Delete
- .Headers(wdHeaderFooterPrimary).Range.ParagraphFormat.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
- End With
- '第2节:目录,有页码!格式:罗马数字
- With .Sections(2).Footers(wdHeaderFooterPrimary)
- .LinkToPrevious = False
- .Range.Delete
- With .PageNumbers
- .NumberStyle = wdPageNumberStyleUppercaseRoman
- .RestartNumberingAtSection = True
- .StartingNumber = 1
- .Add PageNumberAlignment:=wdAlignPageNumberCenter, FirstPage:=True
- End With
- '*********************************
- With .Range.Font
- .NameAscii = "Times New Roman"
- .Size = 9
- .Bold = False
- .ColorIndex = wdBlack
- End With
- End With
- '第3节:正文,有页码!格式:-1-
- For i = 3 To j
- With .Sections(i).Footers(wdHeaderFooterPrimary)
- If k = 1 Then
- .LinkToPrevious = False
- Else
- .LinkToPrevious = True
- End If
- .Range.Delete
- With .PageNumbers
- .NumberStyle = wdPageNumberStyleNumberInDash
- If k = 1 Then
- .RestartNumberingAtSection = True
- Else
- .RestartNumberingAtSection = False
- End If
- .StartingNumber = 1
- .Add PageNumberAlignment:=wdAlignPageNumberCenter, FirstPage:=True
- End With
- '*********************************
- With .Range.Font
- .NameAscii = "Times New Roman"
- .Size = 9
- .Bold = False
- .ColorIndex = wdBlack
- End With
- End With
- Next
- If k = 0 Then
- With .Sections(3).Footers(wdHeaderFooterPrimary)
- .LinkToPrevious = False
- With .PageNumbers
- .RestartNumberingAtSection = True
- .StartingNumber = 1
- End With
- End With
- End If
- End With
-
- Else
-
- If MsgBox("是否顺延页码(否则每节重排)?", 4 + 48) = vbNo Then k = 1
- With ActiveDocument
- j = .Sections.count
-
- .Sections.PageSetup.OddAndEvenPagesHeaderFooter = False
- '第1节:封面,无页码!
- With .Sections(1).Footers(wdHeaderFooterPrimary)
- .Range.Delete
- .Range.ParagraphFormat.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
- End With
-
- With .Sections(1).Footers(wdHeaderFooterPrimary)
- .Range.Delete
- .Range.ParagraphFormat.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
- End With
- '第2节:目录,有页码!格式:罗马数字
- With .Sections(2).Footers(wdHeaderFooterPrimary)
- .LinkToPrevious = False
- .Range.Delete
- With .PageNumbers
- .NumberStyle = wdPageNumberStyleUppercaseRoman
- .RestartNumberingAtSection = True
- .StartingNumber = 1
- .Add PageNumberAlignment:=wdAlignPageNumberOutside, FirstPage:=True
- End With
- '*********************************
- With .Range.Font
- .NameAscii = "Times New Roman"
- .Size = 9
- .Bold = False
- .ColorIndex = wdBlack
- End With
- End With
- '第3节:正文,有页码!格式:-1-
- For i = 3 To j
- With .Sections(i).Footers(wdHeaderFooterPrimary)
- If k = 1 Then
- .LinkToPrevious = False
- Else
- .LinkToPrevious = True
- End If
- .Range.Delete
- With .PageNumbers
- .NumberStyle = wdPageNumberStyleNumberInDash
- If k = 1 Then
- .RestartNumberingAtSection = True
- Else
- .RestartNumberingAtSection = False
- End If
- .StartingNumber = 1
- .Add PageNumberAlignment:=wdAlignPageNumberOutside, FirstPage:=True
- End With
- '*********************************
- With .Range.Font
- .NameAscii = "Times New Roman"
- .Size = 9
- .Bold = False
- .ColorIndex = wdBlack
- End With
- End With
- Next
- If k = 0 Then
- With .Sections(3).Footers(wdHeaderFooterPrimary)
- .LinkToPrevious = False
- With .PageNumbers
- .RestartNumberingAtSection = True
- .StartingNumber = 1
- End With
- End With
- End If
- End With
-
-
-
- End If
-
- End Sub
复制代码
|
|