Excel VBA Checking if Addin Is Installed But Not Open

隐身守侯 提交于 2020-01-05 05:40:28

问题


I have the following code to check if a required addin is installed/available before calling scripts within that Addin from the current context:

Function IsAddinEnabled(addinName as string) As Boolean
    IsAddinEnabled = True
    Dim myAddin As addin
    On Error GoTo NotExists
    Set myAddin = Application.AddIns2(addinName)
    If myAddin.IsOpen = False Then ' this logic is my workaround
        myAddin.Installed = False 'uninstall 
        myAddin.Installed = True ' install to "Open" the addin
    Else
        myAddin.Installed = True 'redundant
    End If
    Exit Function
NotExists:
    IsAddinEnabled = False
End Function

The problem arises when:

myAddin.IsOpen = false I had to add this logic to reinstall the addin. It's a slight nuisance/slow down to uninstall and reinstall the addin. Is there a way to force and Addin to "open" without re-installing the addin?


回答1:


A simpler way is to check if the addin exists in the workbooks collection.

If it does not you can open it as though it was a workbook assuming you know the path.

(don't need to bother with the addins collection)




回答2:


Per @Charles Williams

This is the method I've used:

Function IsAddinEnabled(addinName as string) As Boolean
    IsAddinEnabled = True
    Dim myAddin As addin
    On Error GoTo NotExists
    Set myAddin = Application.AddIns2(addinName)
    If myAddin.IsOpen = False Then ' this logic is my workaround
        Workbooks.Open myAddin.Path & "\" & myAddin.Name 'open the addin, if it's not open
    Else
        myAddin.Installed = True 'redundant
    End If
    Exit Function
NotExists:
    IsAddinEnabled = False
End Function


来源:https://stackoverflow.com/questions/39413928/excel-vba-checking-if-addin-is-installed-but-not-open

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