打开此文档时出错。无效的操作对象

There was an error opening this document. Invalid action object

我正在 VBA 中编写一个子例程来显示 PDF 文档中的页数。这是我的代码(来自我的模块):

Sub PDF_Num_Pages()
   Dim tCount As Long
   Dim objAVDoc As New AcroAVDoc
   Dim objPDDoc As New AcroPDDoc
   Dim objPage As AcroPDPage
   Dim objSelection As AcroPDTextSelect
   Dim objHighlight As AcroHiliteList
   Dim pageNum As Long
   Dim strText As String

   objAVDoc.Open "C:\<path to my file>\simple1.pdf", ""
   Set objPDDoc = objAVDoc.GetPDDoc
   MsgBox objPDDoc.GetNumPages()

End Sub

当我 运行 脚本时,Adobe Acrobat Reader 打开。然后 Adob​​e Acrobat 出现错误:
There was an error opening this document. Invalid action object.

我点击确定。盒子消失了。

然后在Excel,出现我的消息框,显示一个-1。

PDF 的长度为 1 页,因此应显示 1。

Tools->References 中,我检查了 Adobe Acrobat 10.0 Type Library

在我的 Adob​​e Acrobat 文档 (simple1) 中,我启用了安全功能。当我双击它时,我再也看不到 "Enable All Features" 选项了。它会自动打开。

我做错了什么?

函数是否可以写成...

objAVDoc.Open<b>(</b>"C:\<path to my file>simple1.pdf", ""<b>)</b>

...只是一个建议。

我现在开始工作了。我不再将这些对象声明为新对象。 (谢谢 Mathieu。)我找到了另一个 post;这表明在创建对象后声明它们;并做到了。

我还 运行 Adob​​e Acrobat 并进行了一些 PDF 转换(我想知道这是否可能在我的机器上设置了一些以前没有完全设置的东西)。我也为我的 Adob​​e Acrobat 做了一个 "repair"。

Windows 重新启动可能也有帮助。这是工作代码:

Sub PDF_Num_Pages()
   Dim myApp As Acrobat.AcroApp
   Dim objAVDoc As Acrobat.AcroAVDoc
   Dim objPDDoc As Acrobat.AcroPDDoc

   ' create an automation object that references the active copy of Acrobat
   Set myApp = CreateObject("AcroExch.App")
   ' reference the acrobat document we loaded above
   Set objAVDoc = CreateObject("AcroExch.AVDoc")

   objAVDoc.Open "C:\<pdf path>simple1.pdf", ""
   Set objPDDoc = objAVDoc.GetPDDoc
   MsgBox objPDDoc.GetNumPages()

End Sub