Cardinals28
Cardinals28

Reputation: 11

BuiltInDocumentProperties Returns wrong value

I want to get the page count for a specified file but it seems to be getting the wrong value for pages, it's outputting the count as 3 when it really is 6. The code being used is the following:

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)

Upvotes: 0

Views: 477

Answers (1)

Cardinals28
Cardinals28

Reputation: 11

I found a solution to the issue described above, what I needed to do is tell it to repaginate after opening the document. Code that worked:

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)

I'm thinking there's a better solution out there but the above worked for me.

Upvotes: 1

Related Questions