问题
I am trying to write a vba macro for word, where the document will have page numbers, but the alignment of odd page number will be different from the even page. The code that I am presently trying is changing the alignment of both the odd and even pages,which is not desired
ActiveDocument.Sections(i).PageSetup.OddAndEvenPagesHeaderFooter = False
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter.LinkToPrevious
ActiveDocument.Sections(i).Footers(wdHeaderFooterPrimary).LinkToPrevious = False
With ActiveDocument.Sections(i).Footers(1).PageNumbers
.NumberStyle = wdPageNumberStyleArabic
.HeadingLevelForChapter = 0
.IncludeChapterNumber = False
.ChapterPageSeparator = wdSeparatorHyphen
.RestartNumberingAtSection = False
.StartingNumber = starts
.Add (0)
End With
End If
ActiveDocument.Sections(i).PageSetup.OddAndEvenPagesHeaderFooter = True
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
ActiveDocument.Sections(i).Footers(wdHeaderFooterEvenPages).LinkToPrevious = False
WordBasic.InsertAlignmentTab Alignment:=2, Relative:=0, Leader:=0
回答1:
It seems that for odd and even pages you don't set left
and right
positions of page numbers but you need to set outside
and inside
positions of them.
So, try to change this tiny line:
.Add (0)
into one of possible 'odd-even' positions:
.Add wdAlignPageNumberOutside
.Add wdAlignPageNumberInside
Moreover, last line which is trying to insert 'tab' is not necessary then.
来源:https://stackoverflow.com/questions/16079070/assign-even-odd-page-numbers-in-word