Help with Uninstall Event

C

Clinton

Hi

Some thing bizarre is happening! I have an add-in which when uninstalled
through the uninstall event removes a custom toolbar attached to it. Im
using Inno Setup to uninstall this add-in through Automation.

This works perfectly on my windows 2000 machine, but on my windows xp
machine the add-in is removed from the add-in list, but the toolbar isn't.

Both machines are running Excel 2000.

Hopefully a genius out there can help out this non-genius!

Cheers

Clinton
 
B

Bob Phillips

Showing the code might help.

What is Inno Setup?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
C

Clinton

Well, inno setup is actually irrelevant. Here is the VB code that does the
uninstallation. I just put the name of the add-in as listed in Tools|Addins
as the command line parameter(s)

Dim oXL As Object, oAddin As Object
Dim i As Integer

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.
Kill oXL.addins(Trim(argarray(i))).fullname

Next i

oXL.Quit
Set oXL = Nothing

On Error GoTo 0

End Sub
 
B

Bob Phillips

Thought so, but just interested.

Can't run it as you don't give us the GetCommandLine sub.

Are you not explicitly deleting the toolbar?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
C

Clinton

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
 

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