Add in installed and referenced

 ̄綄美尐妖づ 提交于 2019-11-28 09:55:30

问题


I want to check if addin is installed and is referenced. The below code checks for add in is installed or not. How can i check if its referenced in excel.

By Refernced i mean is Tools > Addins > Addins Dailog box > If addins is installed > check if a addin with particular name is checked.

I would like preferably without any loop.

Sub Demo() 
    Dim b As Boolean 
    b = CheckAddin("Solver add-in") 
    MsgBox "Solver is " & IIf(b, "", "not ") & "installed" 
End Sub 

Function CheckAddin(s As String) As Boolean 
    Dim x As Variant 
    On Error Resume Next 
    x = AddIns(s).Installed 
    On Error Goto 0 
    If IsEmpty(x) Then 
        CheckAddin = False 
    Else 
        CheckAddin = True 
    End If 
End Function 

回答1:


Sub Sample()
    Dim wbAddin As Workbook

    On Error Resume Next
    Set wbAddin = Workbooks(AddIns("My Addin").Name)

    If Err.Number <> 0 Then
        On Error GoTo 0
        'Set wbAddin = Workbooks.Open(AddIns("My Addin").FullName)
        Debug.Print "Not Referenced"
    Else
        Debug.Print "Referenced"
    End If
End Sub



回答2:


You need to test is the addin is open, pretty much like any other workbood. This will return True if an addin is loaded:

Function AddinIsLoaded(AddinName As String) As Boolean
On Error Resume Next
AddinIsLoaded = Len(Workbooks(AddIns(AddinName).Name).Name) > 0
End Function

For example:

Sub Test
Debug.Print AddinIsLoaded("Solver add-in")
End Sub



回答3:


I've had a problem that even when the function returns True, I would still get an error when trying to use that addin. It turns out, an addin can be installed, but not "open". So, in addition to checking for the addin, I also check if the addin file is open. If not, I open the addin. See my question and answer here:

Excel VBA Checking if Addin Is Installed But Not Open



来源:https://stackoverflow.com/questions/15951518/add-in-installed-and-referenced

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!