Enable COM addins in Excel through VBA

后端 未结 3 842
面向向阳花
面向向阳花 2020-12-21 14:14

I need to enable COM addins through VBA. The addins already exists under COM addins, but become unchecked when Excel crashes.

Sub hyp()
    Dim objAddIn As O         


        
3条回答
  •  余生分开走
    2020-12-21 15:13

    I have the same system block mentioned earlier where system privileges won't allow me to use Application.COMAddIns(Name).Connect = True. This is a bit of a workaround, but to get the COM add ins box to pop up you can use SendKeys to pull it up. Keep in mind that SendKeys only excutes at the end of a run on Excel 2010 onwards, so to get it working correctly you would need to check if the user is connected to the add-in first thing. If so, call another sub; if not use SendKeys to get the dialog open and end the sub. These are the keystrokes that worked for me, there may need to be some edits depending on how many options are in your menus.

    Sub test()
    
    'Checks if COM is installed and active
    comFound = False
    comRibbon = True
    For i = 1 To Application.COMAddIns.Count
        If Application.COMAddIns(i).Description = "NAME" Then
            comFound = True
            If Application.COMAddIns(i).Connect = False Then
                comRibbon = False
            End If
            Exit For
        End If
    Next i
    
    'Exits sub if not installed
    If comFound = False Then
        MsgBox ("You do not have NAME installed.")
        Exit Sub
    End If
    
    'Directs user to rest of code if active, otherwise opens dialog
    If comRibbon = True Then
        Call test2
    Else
        MsgBox ("Please select NAME in the following dialog before rerunning.")
    End If
    
    SendKeys "%FT{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{TAB}{TAB}{TAB}{DOWN}{DOWN}{TAB}~", True
    
    End Sub
    
    Sub test2()
        'Rest of code
    End Sub
    

提交回复
热议问题