如何检查是否在excel中创建了activex对象?

时间:2018-06-02 11:01:29

标签: excel-vba vba excel

我遇到了一个用于获取页码的PDF对象,

Set AcroExchApp = CreateObject("AcroExch.App")    'Acrobat Exchange
Set AcroExchPDDoc = CreateObject("AcroExch.PDDoc")

在某些机器上,代码在此行上会失败。

如何让它优雅地失败?

1 个答案:

答案 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