3
votes

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
how do you define no_format variable here?? and other variables like starts, continue, align?? did you try to debug this code step-by-step?? Moreover, add bigger part of your code that would include opening for end if statement which is in 5th row before end... - Kazimierz Jawor
no_format is a variable =1 signifying the page number style,continue is true and false for if it continues marking pages with the previous section, and align =0 for left alignment and align2 is alignment for right alignment, if-endif is used for positioning of page number in header or footer - Sanghita
thanks, these are important information. could you extend your code a bit too?? - Kazimierz Jawor
hope it's fixed. any feedback if it's working is welcome... - Kazimierz Jawor

1 Answers

2
votes

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.