我遇到了一个用于获取页码的PDF对象,
Set AcroExchApp = CreateObject("AcroExch.App") 'Acrobat Exchange
Set AcroExchPDDoc = CreateObject("AcroExch.PDDoc")
在某些机器上,代码在此行上会失败。
如何让它优雅地失败?
答案 0 :(得分:0)
我终于找到了一种优雅的方法来处理错误,提示用户安装所需的应用程序
On Error Resume Next
Set AcroExchApp = CreateObject("AcroExch.App") 'Acrobat Exchange
Set AcroExchPDDoc = CreateObject("AcroExch.PDDoc")
'AcroExchApp.Show ' Show the Acrobat Exchange window
On Error GoTo 0
'check if activex pdf object exists
If AcroExchApp Is Nothing Or AcroExchPDDoc Is Nothing Then
MsgBox "Adobe Acrobat Pro Activex control not found." & _
vbCrLf & "Please install Adobe Acrobat Pro and try again"
Exit Sub
End If