If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Incorrect {PAGE} fields in document compiled with VBA from others docs
The situation:
Having successfully compiled (using VBA) a large document from 100+ smaller documents, I'm now faced with a page numbering problem. Although the page number in the 'status' bar at the bottom of Word gives the correct page number, a {PAGE} field inserted into the footer of each page gives an incorrect value - out of 220 pages, it reads page 1 to 82 of 220 ( Page 1 of 220, Page 2 of 220 etc), then Page 1 to 4 of 220, then Page 1 to 4 of 220, etc, until the last 'group' reads Page 1 to 58 of 220 - v. weird as these numbers do not tally up with the number of pages in the inserted files, which are mostly just two page files. I have already tried: 1) Programmatically numbering these pages by looping through each page and writing manual values to the footers - this does not work due to the fact that the section breaks often display the same page number twice. 2) Programmatically going to each footer, deleting the incorrect values, doing an activedocument.repaginate, adding a {PAGE} field, then doing activedocument.repaginate again. In addition to all of the above, this actually worked at one point in the past without any programmatic adjustments after generating the document from the source documents. This problem has cropped up after I tried to speed up execution by using word.application.visible = true. I removed the code for hiding the application, but the problem still remained even after this. There is unique information beside the page number in each section footer, so I can't just redo all the sections. Any suggestions would be most welcome. Many thanks, Ganeth |
#2
|
|||
|
|||
Incorrect {PAGE} fields in document compiled with VBA from others docs
This always happens when I post a question in haste - two hours later I solve it! The following code corrects the problem I described above:
Function correct_dodgy_page_numbering() Dim sections_count As Integer 'determine number of sections in the doc sections_count = ActiveDocument.Sections.Count 'go to section one Selection.GoTo what:=wdGoToSection, which:=wdGoToFirst, Count:=1, name:="" 'set page numbering to start at one in this section ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter With Selection.HeaderFooter.PageNumbers .NumberStyle = wdPageNumberStyleArabic .HeadingLevelForChapter = 0 .IncludeChapterNumber = False .ChapterPageSeparator = wdSeparatorHyphen .RestartNumberingAtSection = True .StartingNumber = 1 End With 'loop through all the remaining sections For i = 2 To sections_count 'goes to section number i Selection.GoTo what:=wdGoToSection, which:=wdGoToFirst, Count:=i, name:="" 'open footer ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter 'set page numbering to continue from the previous section With Selection.HeaderFooter.PageNumbers .NumberStyle = wdPageNumberStyleArabic .HeadingLevelForChapter = 0 .IncludeChapterNumber = False .ChapterPageSeparator = wdSeparatorHyphen .RestartNumberingAtSection = False .StartingNumber = 0 End With Next i 'return to main document ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 'return to top of doc Selection.GoTo what:=wdGoToPage, which:=wdGoToNext, name:="1" End Function Hope that helps other people apart from myself! Ganeth |
Thread Tools | |
Display Modes | |
|
|