我知道在VBA中,在文档中,我可以使用ActiveDocument.Range.Information(wdNumberOfPagesInDocument)
获取页数,但我无法使用Microsoft.Office.Interop.Word
在VB.Net中找到它的等效内容。
是否有其他方式可以达到文档中的页数?
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
答案 0 :(得分:1)
一种方法是获取最后一页编号:
lastPageNumber = objDoc.Words.Last.Information[Wd.WdInformation.wdActiveEndPageNumber]
答案 1 :(得分:-2)
当您在VBA中编码时,父应用程序(Word,Excel等)的命名空间是显而易见的,因此诸如wdNumberOfPagesInDocument之类的常量具有定义。使用Microsoft.Office.Interop.Word,您需要提供命名空间信息;例如:
...
With objDoc
pages = .Range.Information(Word.WdInformation.wdNumberOfPagesInDocument)
End With
....