Assign even odd page numbers in a word

I am trying to write a vba macro for a word where the document will have page numbers, but the alignment of the odd page number will be different from the even page. The code I'm trying now changes the alignment of both odd and even pages, which is undesirable

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 
+3
source share
1 answer

It seems that for odd and even pages you do not set the left and right positions of the page numbers, but you need to set them outside and inside .

So try changing this tiny line:

 .Add (0) 

to one of the possible "odd-even" positions:

 .Add wdAlignPageNumberOutside .Add wdAlignPageNumberInside 

In addition, the last line that tries to insert a tab is not needed.

+2
source

Source: https://habr.com/ru/post/1488428/


All Articles