mekkanizer
mekkanizer

Reputation: 741

vba word - force pages count

I have a script that browses through document using

Set main_browser = Application.Browser
main_browser.Target = wdBrowsePage
main_browser.Next

It works as expected only if you press Ctrl+End before the execution or wait long enough so that Word counts the amount of pages in document (it's usually over a thousand pages, so it takes some time)

I am now trying to add "lotsa files" functionality (select a group of files in dialog box and process them all). I discovered the fact that when Word opens a document inside a VBA script, it only processes first couple of pages and moves on. All I could think of is

Selection.GoTo What:=wdGoToPage, Which:=wdGoToLast
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst

and it does not help.

So the question is: how to make Word "wait" while it counts pages or (much better) manually force it to count them?

Upvotes: 0

Views: 473

Answers (1)

Seth
Seth

Reputation: 199

Application.ActiveDocument.Repaginate is what you need. You should call it before you call any of the other code.

Upvotes: 0

Related Questions