Reputation: 2455
I know in VBA, within a document, I can get page count using ActiveDocument.Range.Information(wdNumberOfPagesInDocument)
, But I can't find an equivalent of it in VB.Net using Microsoft.Office.Interop.Word
.
Is there, perhaps another way I can attain the quantity of pages in a document?
Public Class Window
'set form level declarations
Dim appPath As String
Dim objWordApp As New Word.Application
Dim objDoc As Word.Document
Dim errorPosition As String
Private Sub Window_Load(ByVal sender As System.Object, e As System.EventArgs) Handles MyBase.Load
objDoc = objWordApp.ActiveDocument
With objDoc
pages = .ActiveDocument.Range.Information(wdNumberOfPagesInDocument)
End With
objDoc = Nothing
End Sub
objWordApp = Nothing
End Class
Upvotes: 1
Views: 3091
Reputation: 1
In the Office.Interop.Word Verion 15.0.0
you can try paginate. like this.
objWordApp.Options.Pagination = true; objWordApp.ActiveDocument.Repagenate();
And Then DocumentFormat.OpenXml Version 2.12.3
using (WordprocessingDocument document = WordprocessingDocument.Open(filePath, false)) { document.ExtentedFilePropertuesPart.Properties.Pages.Text }
Upvotes: 0
Reputation: 16968
A way is to get last page number:
lastPageNumber = objDoc.Words.Last.Information[Wd.WdInformation.wdActiveEndPageNumber]
Upvotes: 3
Reputation: 90
When you code in VBA, the namespace of the parent application (Word, Excel, etc.) is obvious, so constants such as wdNumberOfPagesInDocument have definitions. With Microsoft.Office.Interop.Word you need to provide the namespace information; for example:
...
With objDoc
pages = .Range.Information(Word.WdInformation.wdNumberOfPagesInDocument)
End With
....
Upvotes: -2