Reputation: 12353
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
Upvotes: 3
Views: 8221
Reputation: 1024
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
Upvotes: 0
Reputation: 149335
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
Upvotes: 5
Reputation: 27488
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
Upvotes: 3