我想得到指定文件的页数,但它似乎得到了错误的页面值,当它真的是6时,它将计数输出为3.正在使用的代码如下:
Dim myWordDoc As Microsoft.Office.Interop.Word.Document
Dim myWordApp As Microsoft.Office.Interop.Word.Application
myWordApp = New Microsoft.Office.Interop.Word.Application
myWordDoc = myWordApp.Documents.Open("C:\Users\user\Desktop\TestInsert.docx")
MsgBox(myWordDoc.BuiltInDocumentProperties("Number of Pages").value)
答案 0 :(得分:1)
我找到了上述问题的解决方案,我需要做的是在打开文档后告诉它重新分页。有效的代码:
Dim myWordDoc As Microsoft.Office.Interop.Word.Document
Dim myWordApp As Microsoft.Office.Interop.Word.Application
myWordApp = New Microsoft.Office.Interop.Word.Application
myWordDoc = myWordApp.Documents.Open("C:\Users\user\Desktop\TestInsert.docx")
myWordDoc.Repaginate()
MsgBox(myWordDoc.BuiltInDocumentProperties("Number of Pages").value)
我认为那里有更好的解决方案,但上述方法对我有用。