Hi. Sorry. Not used to someone being so helpful! Here is the entire code,
including the uninstall event. As mentioned, works perfectly on Win2000 but
doesn't remove the Toolbar in WinXP. On my WinXP machine, I also set Macro
Security to Low but it made no difference.
Thanks
Clinton
(remove DIE SPAM DIE from my email address to email direct)
Public argarray() As String
Sub Main()
'Created by Clinton Eidelman, November 2003. Updated March 2004.
'This is run by uninstall routine within InnoSetup when the Add-in
'in uninstalled. It removes the Add-in reference from the Tools | Add-in
menu, and then deletes the
'add-in from the add-ins folder.
'The command line parameters must be separated by COMMA'S, and must
represent the Add-in Title listed
'in the Tools | Add-ins and NOT the name of the toolbar!!!
On Error Resume Next
Dim oXL As Object, oAddin As Object
Dim i As Integer
Const strtoolbar = "Phone Analyser"
Set oXL = CreateObject("Excel.Application")
Call GetCommandLine
For i = 1 To UBound(argarray)
'if inverted commas are included in commandline, would cause error
'as add-in file name would not exist. this function removes the inverted
commas
If Len(argarray(i)) = 0 Then
MsgBox "No Command Line arguments - cannot automatically remove
Excel Add-in(s).", vbCritical, "No Command Line Arguments"
End
End If
argarray(i) = ReplaceLetter(argarray(i), Chr(34), "")
'unticks add-in in Tools|Add-ins and runs the uninstall event!
'note the trim. this is to cater for parameters separated by a comma,
and also a comma and space
oXL.addins(Trim(argarray(i))).Installed = False
'once uninstalled, can delete Add-in. However, this doesn't remove the
deleted add-in from
'Tools | Add-ins. To do this is a mission!
Kill oXL.addins(Trim(argarray(i))).fullname
'following two lines will cause error if add-in is installed and upon
uninstallation the toolbar is removed
'if the toolbar has been removed tbar will not equal "Nothing" as an
error would be generated
'hence the on error resume next at the top of the code
Set tbar = oXL.commandbars(strtoolbar) 'remove toolbar if exist
If Not tbar Is Nothing Then tbar.Delete
Next i
oXL.Quit
Set oXL = Nothing
On Error GoTo 0
End Sub
Public Function ReplaceLetter(StringToBeReplaced As String, LetterToReplace
As String, ReplacementLetter As String) As String
Dim i As Integer, StrTemp As String, StrResult As String
For i = 1 To Len(StringToBeReplaced)
StrTemp = Mid$(StringToBeReplaced, i, 1)
If StrTemp = LetterToReplace Then StrTemp = ReplacementLetter
StrResult = StrResult & StrTemp
Next i
ReplaceLetter = StrResult
End Function
Sub GetCommandLine(Optional MaxArgs)
'Declare variables.
Dim C, cmdline, CmdLnLen, InArg, i, NumArgs
'See if MaxArgs was provided.
If IsMissing(MaxArgs) Then MaxArgs = 20
'Make array of the correct size.
ReDim argarray(MaxArgs)
NumArgs = 0: InArg = False
'Get command line arguments.
cmdline = Command()
CmdLnLen = Len(cmdline)
'Go thru command line one character
'at a time.
For i = 1 To CmdLnLen
C = Mid(cmdline, i, 1)
'Test for space or tab.
If (C <> ",") Then
'Neither space nor tab.
'Test if already in argument.
If Not InArg Then
'New argument begins.
'Test for too many arguments.
If NumArgs = MaxArgs Then Exit For
NumArgs = NumArgs + 1
InArg = True
End If
'Concatenate character to current argument.
argarray(NumArgs) = argarray(NumArgs) & C
Else
'Found a space or tab.
'Set InArg flag to False.
InArg = False
End If
Next i
'Resize array just enough to hold arguments.
ReDim Preserve argarray(NumArgs)
'Return Array in Function name.
End Sub
****
Private Sub Workbook_AddinUninstall()
'This removes the toolbar when the add-in is uninstalled
Dim tbar As Object
On Error Resume Next
Set tbar = Application.CommandBars("Phone Analyser")
If Not tbar Is Nothing Then tbar.Delete
End Sub