在Microsoft Word VBA中,如何检查重新分页?
我正在使用MicrosoftWord2007。我用VBA打开了一些文档,我需要对它们做一些工作。但是,当一个文件刚刚打开时,VBA会执行此重新分页操作,并且不会等到它完成后再继续。所以会发生的是,我的代码会出错,因为它认为打开的文档只有几页长,而它要长得多 我的代码:在Microsoft Word VBA中,如何检查重新分页?,vba,ms-word,Vba,Ms Word,我正在使用MicrosoftWord2007。我用VBA打开了一些文档,我需要对它们做一些工作。但是,当一个文件刚刚打开时,VBA会执行此重新分页操作,并且不会等到它完成后再继续。所以会发生的是,我的代码会出错,因为它认为打开的文档只有几页长,而它要长得多 我的代码: Documents.Open fileName:="C:\file.doc", Visible:=False MsgBox ActiveDocument.BuiltInDocumentProperties("Number of P
Documents.Open fileName:="C:\file.doc", Visible:=False
MsgBox ActiveDocument.BuiltInDocumentProperties("Number of Pages")
我尝试过使用睡眠,但不起作用,有什么想法吗?试试这个:
Dim NewDoc As Document
Dim PageCount As Long
Set NewDoc = fileName:="C:\file.doc", Visible:=False
PageCount = NewDoc.ComputeStatistics(wdStatisticPages)
MsgBox PageCount
好吧,我找到了一份工作。我还没试过Nick下面的答案,看起来很合法。无论如何,我所做的就是一段一段地循环浏览整个文档。虽然效率不高,但它确实有效。