Assign even odd page numbers in word

霸气de小男生 提交于 2019-12-23 17:59:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!