我知道在VBA中,在一個文檔中,我可以使用ActiveDocument.Range.Information(wdNumberOfPagesInDocument)
得到頁數,但我無法在VB.Net中使用Microsoft.Office.Interop.Word
找到它的等效值。
有沒有,也許我可以通過另一種方式獲得文檔中的頁面數量?字互操作和獲取頁數
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
WdInformation.wdNumberOfPagesInDocument? – braX
「Microsoft.Office.Interop」命名空間反映了Office VBA提供的API(儘可能接近),因此VBA中可能實現的任何操作都可以使用「Microsoft.Office.Interop」命名空間在.NET中完成。你在哪裏卡住/有問題?它是否獲得'ActiveDocument'?在這種情況下:您可以從['Word.Application'類](https://msdn.microsoft.com/en-us/library/microsoft.office.interop.word._application.activedocument)獲取'ActiveDocument'。 ASPX)。 – bassfader
@bassfader我已經嘗試過,但無法使其正常工作。我會發布一些我的代碼。 – Jaberwocky