![]() |
|
#1
|
|||
|
|||
![]()
Hello, Greeting to Everyone
While setting/adjusting the pagenumbers via VBA or pywin (python) the first page header gets expand which distrupts the formatting of every other pages. Here is the code recorded from word Code:
Sub AdjustpageNumbers() With Selection.Sections(1).Headers(1).PageNumbers .NumberStyle = wdPageNumberStyleArabic .HeadingLevelForChapter = 0 .IncludeChapterNumber = False .ChapterPageSeparator = wdSeparatorHyphen .RestartNumberingAtSection = True .StartingNumber = 84 End With End Sub I have attached the snipped images of before and after running the code. Please have a look. first page does not have a page number (header) because the document is set to Different First page = True and Different odd and even page = True The main concern is that I have defined some functions that continue page numbers in multiple documents. But in some cases, the function returns wrong page numbers because whenever the function to set a new page number is called or if the header is accessed through the code, an extra paragraph is appears in the first page of the document which causes all the following pages to overflow. Hence, returning the false page number (in most cases total page + 1). I wanted to know if this could be avoided. Or if i am doing anything wrong. |
#2
|
||||
|
||||
![]()
Try something along the lines of:
Code:
Sub AdjustpageNumbers() With ActiveDocument.Sections.First .PageSetup.DifferentFirstPageHeaderFooter = True .PageSetup.OddAndEvenPagesHeaderFooter = True With .Headers(wdHeaderFooterFirstPage).PageNumbers .StartingNumber = 84 .RestartNumberingAtSection = True End With With .Headers(wdHeaderFooterEvenPages) .PageNumbers.NumberStyle = wdPageNumberStyleArabic .Range.Fields.Add .Range.Characters.Last, wdFieldPage, , False End With With .Headers(wdHeaderFooterPrimary) .PageNumbers.NumberStyle = wdPageNumberStyleArabic .Range.Fields.Add .Range.Characters.Last, wdFieldPage, , False End With End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Thank you for the response, Macropod. I am very grateful. The code you provided inserts the page number, but the problem still exists, and it seems like (Hard-coding it to take as little space as possible) is the only option for now.
For now, I am using Code:
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader With Selection .font.Size = 1 .font.spacing = 0 .ParagraphFormat.spaceBefore = 0 .ParagraphFormat.spaceAfter = 0 .ParagraphFormat.LineSpacingRule = wdLineSpaceMultiple .ParagraphFormat.lineSpacing = LinesToPoints(1) End With |
#4
|
||||
|
||||
![]()
I am unable to reproduce the problem. Perhaps you could upload a document with some representative data (delete anything sensitive) for testing? You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
![]() Quote:
|
![]() |
Tags |
setting page numbers |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Even page numbers disappear when setting up opposite headers. | slromine | Word | 2 | 08-02-2019 08:05 AM |
![]() |
thefonebug | Word | 12 | 10-24-2016 05:18 AM |
How do I edit my TOC to reference the section numbers instead of the page numbers??? | mikey386 | Word | 0 | 12-17-2014 02:34 PM |
How do I refer to page numbers, when the numbers change as I prepare the document? | StevenD | Word | 5 | 11-29-2012 12:52 AM |
![]() |
gracie5290 | Word | 1 | 02-02-2012 11:41 PM |