Incorrect {PAGE} fields in document compiled with VBA from others docs

G

Guest

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

Ganet
 
G

Guest

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 Intege

'determine number of sections in the do
sections_count = ActiveDocument.Sections.Coun

'go to section on
Selection.GoTo what:=wdGoToSection, which:=wdGoToFirst, Count:=1, name:="

'set page numbering to start at one in this sectio
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFoote

With Selection.HeaderFooter.PageNumber
.NumberStyle = wdPageNumberStyleArabi
.HeadingLevelForChapter =
.IncludeChapterNumber = Fals
.ChapterPageSeparator = wdSeparatorHyphe
.RestartNumberingAtSection = Tru
.StartingNumber =
End Wit

'loop through all the remaining section
For i = 2 To sections_coun

'goes to section number
Selection.GoTo what:=wdGoToSection, which:=wdGoToFirst, Count:=i, name:="

'open foote
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFoote

'set page numbering to continue from the previous sectio
With Selection.HeaderFooter.PageNumber
.NumberStyle = wdPageNumberStyleArabi
.HeadingLevelForChapter =
.IncludeChapterNumber = Fals
.ChapterPageSeparator = wdSeparatorHyphe
.RestartNumberingAtSection = Fals
.StartingNumber =
End Wit

Next

'return to main documen
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocumen

'return to top of do
Selection.GoTo what:=wdGoToPage, which:=wdGoToNext, name:="1

End Functio

Hope that helps other people apart from myself

Ganeth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top