开发者

In Microsoft Word VBA, how do I check for repagination?

开发者 https://www.devze.com 2023-01-24 10:43 出处:网络
I am using Microsoft Word 2007.I open up some document with VBA and I need to do some work on them.However when a file is just opened, VBA do this repagination and doesn\'t wait for it to finish befor

I am using Microsoft Word 2007. I open up some document with VBA and I need to do some work on them. However when a file is just opened, VBA do this repagination and doesn't wait for it to finish before continuing. So what would happen is that my code would then error because it think the opened document is only a few pages long when it's much longer.

My Code:

Documents.Open fileName:="C:\file.doc", Visible:=False
MsgBox ActiveDocum开发者_C百科ent.BuiltInDocumentProperties("Number of Pages")

I have tried to use sleep but it doesn't work, any ideas?


Try this:

Dim NewDoc As Document
Dim PageCount As Long

Set NewDoc = fileName:="C:\file.doc", Visible:=False
PageCount = NewDoc.ComputeStatistics(wdStatisticPages)

MsgBox PageCount
0

精彩评论

暂无评论...
验证码 换一张
取 消