简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM