Subscript error in 2007 when testing if Addin is installed

X

XP

In Office 2007, I'm using the following function to determine whether an
Add-in is installed, but if the answer is "False", rather than false, I get
"Subscript out of range" error. Any idea what I'm doing wrong? How can I get
this to run right?

Private Function AddInInstalled(argName As String) As Boolean
'return true if an addin is installed:
If AddIns(argName).Installed = True Then
AddInInstalled = True
Else
AddInInstalled = False
End If
End Function

Thanks in advance...
 
B

Bernie Deitrick

Is the error on the line
If AddIns(argName).Installed = True Then

If so, then try:

If cBool(AddIns(argName).Installed) = True Then


HTH,
Bernie
MS Excel MVP
 
X

XP

Hi Bernie and thanks.

That is the line where the error occurs, however your suggestion still fails
to prevent a subscript error if a "False" reply is generated...

Any other suggestions?
 
D

Dave Peterson

This worked ok in xl2003:

Option Explicit
Private Function AddInInstalled(argName As String) As Boolean
AddInInstalled = False
On Error Resume Next
AddInInstalled = CBool(Application.AddIns(argName).Installed)
On Error GoTo 0
End Function
Sub testme()
MsgBox AddInInstalled("analysis toolpak")
MsgBox AddInInstalled("qwer")
End Sub
 
B

Bernie Deitrick

Try it with an On Error trap control:

Sub TryNow()
MsgBox AddInInstalled("Analysis Toolpak")
MsgBox AddInInstalled("Fred")
End Sub

Private Function AddInInstalled(argName As String) As Boolean
'return true if an addin is installed:
Dim myName As String
AddInInstalled = False
On Error GoTo NotInstalled
myName = AddIns(argName).Name
AddInInstalled = AddIns(argName).Installed
NotInstalled:
End Function


HTH,
Bernie
MS Excel MVP
 
X

XP

Thanks Dave and Bernie,

After trial and error, I also came up with something that works, FYI:

Private Function AddInInstalled(argAddInTitle As String) As Boolean
'return true if an addin is installed:
On Error GoTo xERR
If AddIns(argAddInTitle).Installed = True Then AddInInstalled = True
Exit Function
xERR: AddInInstalled = False
End Function

Thanks for your assistance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top