|
假如一个文档,要插入奇偶页不同的页码,并且用vba实现,我录制了以下代码,如果页面多于2页,且光标定位于奇数页,这个代码好是可以运行,如果光标定位在偶数页就出错,或者只有一页时代码就无法运行,你可能会说等大于1页再运行这个代码,但我怕忘记加页码,喜欢新建文档后就加入页面,而且这个贴主要是想请教下,只有一页的情况下,怎么用vba插入奇偶页不同的页码,望高人指点
Sub Macro3()
With ActiveDocument.PageSetup
.OddAndEvenPagesHeaderFooter = True
End With
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
With Selection.ParagraphFormat
.CharacterUnitRightIndent = 1
End With
Selection.Font.Name = "Times New Roman"
Selection.Font.Size = 14
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage
ActiveWindow.ActivePane.View.NextHeaderFooter
With Selection.ParagraphFormat
.CharacterUnitLeftIndent = 1
End With
Selection.Font.Name = "Times New Roman"
Selection.Font.Size = 14
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub |
|