Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Microsoft Word VBA中,如何检查重新分页?_Vba_Ms Word - Fatal编程技术网

在Microsoft Word 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

我正在使用MicrosoftWord2007。我用VBA打开了一些文档,我需要对它们做一些工作。但是,当一个文件刚刚打开时,VBA会执行此重新分页操作,并且不会等到它完成后再继续。所以会发生的是,我的代码会出错,因为它认为打开的文档只有几页长,而它要长得多

我的代码:

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下面的答案,看起来很合法。无论如何,我所做的就是一段一段地循环浏览整个文档。虽然效率不高,但它确实有效。