|
Sub 插入页码_外侧2()
Dim S As Section
Dim n As String
Dim asection As Section
Application.ScreenUpdating = False '关闭屏幕刷新
On Error Resume Next '设置错误处理
Dim 节 As Section
Dim 总节数 As Long, 计数器 As Long
If Documents.Count <> 0 Then
总节数 = ActiveDocument.Sections.Count
Else
Exit Sub '如果没有打开文档直接退出
End If
For 计数器 = 2 To 总节数
With ActiveDocument
If .Sections(计数器).PageSetup.Orientation <> .Sections(计数器 - 1).PageSetup.Orientation Or wdOrientLandscape Then
.Sections(计数器).Footers(wdHeaderFooterPrimary).LinkToPrevious = False
.Sections(计数器).Footers(wdHeaderFooterEvenPages).LinkToPrevious = False
'如果本节页面方向和前节页面方向不同,则关闭本节同前开关设置
End If
End With
Next 计数器 '取消所有节的同前开关设置
For Each asection In ActiveDocument.Sections
With asection.Headers(wdHeaderFooterPrimary)
.Range.Delete
.Range.ParagraphFormat.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
End With
Next
'删除页脚
For Each asection In ActiveDocument.Sections
With asection.Footers(wdHeaderFooterPrimary)
.Range.Delete
.Range.ParagraphFormat.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
End With
With asection.Footers(wdHeaderFooterEvenPages)
.Range.Delete
.Range.ParagraphFormat.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
End With
Next
For Each S In ActiveDocument.Sections
S.Footers(1).Range.Delete
With S.Footers(1).Range.Sections(1).Headers(1).PageNumbers
.NumberStyle = wdPageNumberStyleArabic
.HeadingLevelForChapter = 0
.IncludeChapterNumber = False
.ChapterPageSeparator = wdSeparatorHyphen
.RestartNumberingAtSection = False
.StartingNumber = 0
End With
S.Footers(1).PageNumbers.Add 4, True
With S.Footers(wdHeaderFooterPrimary).Range.Frames(1).Range
.Select
With Selection
With .Font
.Name = "宋体"
.Name = "Times New Roman"
.Size = 9
End With
.ParagraphFormat.CharacterUnitRightIndent = 1.5
End With
End With
With S.Footers(wdHeaderFooterEvenPages).Range.Frames(1).Range
.Select
With Selection
.InsertBefore n
With .Font
.Name = "宋体"
.Name = "Times New Roman"
.Size = 9
End With
.ParagraphFormat.CharacterUnitRightIndent = 1.5
End With
End With
Next
ActiveWindow.ActivePane.Close
ActiveWindow.View.Type = wdPrintView
For 计数器 = 2 To 总节数
ActiveDocument.Sections(计数器).PageSetup.OddAndEvenPagesHeaderFooter = True
If ActiveDocument.Sections(计数器).PageSetup.Orientation = wdOrientLandscape Then
'如果是横向页面,则进行调整
With ActiveDocument.Sections(计数器).Footers(wdHeaderFooterPrimary).Range.Frames(1)
.Width = CentimetersToPoints(0.42)
.HeightRule = wdFrameAtLeast
.Height = CentimetersToPoints(1.05)
.HorizontalPosition = MillimetersToPoints(16) '页码距短边15毫米,左下位置
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.VerticalPosition = MillimetersToPoints(188)
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.HorizontalDistanceFromText = MillimetersToPoints(0)
.VerticalDistanceFromText = MillimetersToPoints(0)
.Range.Orientation = wdTextOrientationDownward '调整页码文字方向
End With
With ActiveDocument.Sections(计数器).Footers(wdHeaderFooterEvenPages).Range.Frames(1)
.Width = CentimetersToPoints(0.42)
.HeightRule = wdFrameAtLeast
.Height = CentimetersToPoints(1.05)
.HorizontalPosition = MillimetersToPoints(16) '页码距短边15毫米,右下位置
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.VerticalPosition = MillimetersToPoints(15)
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.HorizontalDistanceFromText = MillimetersToPoints(0)
.VerticalDistanceFromText = MillimetersToPoints(0)
.Range.Orientation = wdTextOrientationDownward '调整页码文字方向
End With
End If
ActiveDocument.Sections(计数器).Headers(wdHeaderFooterPrimary) _
.Range.ParagraphFormat.Borders(wdBorderBottom).LineStyle = wdLineStyleNone '用于防止页眉出现横线
ActiveDocument.Sections(计数器).Headers(wdHeaderFooterEvenPages) _
.Range.ParagraphFormat.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
With ActiveDocument.Sections(计数器).Footers(wdHeaderFooterEvenPages).Range.Font
.Name = "Times New Roman"
.Size = 9
End With
Next 计数器
Application.ScreenUpdating = True '恢复屏幕刷新
End Sub |
|