Enable COM addins in Excel through VBA

2019-08-09 18:20发布

I need to ENABLE COM addins through VBA. The addins already exists under COM addin's, but get unchecked when my excel crash. Can you please help me with this:

Sub hyp()
 Dim objAddIn As Object
  For i = 1 To Application.COMAddIns.Count

Set objAddIn = Application.COMAddIns.Item(i)
On Error Resume Next
If Application.COMAddIns.Item(i).Description = "Oracle Smart View for Office" Then
'MsgBox Application.COMAddIns.Item(i).Description
'NEED TO ENABLE THE COM ADDIN

Else
End If
Next i
End Sub

2条回答
萌系小妹纸
2楼-- · 2019-08-09 18:39
Public Sub Connect_COM_AddIn(Name As String)

    Dim ndx As Integer

    For ndx = 1 To Application.COMAddIns.Count
        If Application.COMAddIns(ndx).Description = Name Then
            Application.COMAddIns(ndx).Connect = True
            Exit For
        End If
    Next
End Sub
查看更多
Anthone
3楼-- · 2019-08-09 19:00

A simpler alternative to the answer of Excel Developers that worked for me is to index the com add in directly by its string name instead of looping through the com add ins using an integer index and comparing to the description. In particular, this code worked for me (I've included a connect and disconnect version):

Public Sub Connect_COM_AddIn(Name As String)
    Application.COMAddIns(Name).Connect = True
End Sub

Public Sub Disconnect_COM_AddIn(Name As String)
    Application.COMAddIns(Name).Connect = False
End Sub
查看更多
登录 后发表回答