Install & Uninstall add-ins with a VB 6.0-based approach

XL-Dennis

Well-known Member
Joined
Jul 27, 2002
Messages
1,920
I usually use a swedish software for creating setups for Excel add-ins (both xla and COM Add-ins) which also controls the activation.

Therefore I have not previous thought of how to solve it in other ways.

Since I'm not fond of using a bunch of Windows API I decided to use an ActiveX Server (RegObj.dll) to control the registry.

It can be downloaded from:
http://msdn.microsoft.com/vbasic/downloads/addins/components/default.aspx

Below You find the code for both installing and uninstalling add-ins.

It's the first draft and therefore I did not create functions but will later do it.

Code:
Option Explicit

Private Sub Uninstall_Click()
Dim objRootKey As RegKey
Dim objStartKey As RegKey
Dim objValue As RegValue
Dim stName As String
    
Const stSubRoot1 As String = "Software\Microsoft\Office\10.0\Excel\Options"
Const stSubRoot2 As String = "Software\Microsoft\Office\10.0\Excel\Add-in Manager"
Const stAddin As String = "C:\DDE\Test.xla"

'Get the predefined root-key.
Set objRootKey = RegKeyFromHKey(HKEY_CURRENT_USER)

'Parse the subkey.
Set objStartKey = objRootKey.ParseKeyName(stSubRoot1)

'Loop through the subkeys Options values to obtain the correct OPEN-name
'for the add-in.
'This is applicable when add-ins are activated.
For Each objValue In objStartKey.Values
    If objValue.Name Like "OPEN*" Then
        If objValue.Value = """" & stAddin & """" Or _
           objValue.Value = stAddin Then
            stName = objValue.Name
            Exit For
        End If
    End If
Next objValue

'Loop through the subkey Add-in Manager names to obtain the correct name.
'This is applicable when add-ins are deactivated.
If Not stName = "" Then
    Set objStartKey = objRootKey.ParseKeyName(stSubRoot2)
    For Each objValue In objStartKey.Values
        If objValue.Name = stAddin Then
            stName = objValue.Name
            Exit For
        End If
    Next objValue
End If

If stName = "" Then
    MsgBox "Not able to locate the add-in " & stAddin & "!", vbCritical
Else
    'Remove the add-in.
    objStartKey.Values.Remove stName
End If
  
'Release objects from memory.
Set objValue = Nothing
Set objStartKey = Nothing
Set objRootKey = Nothing
    
End Sub

Private Sub Install_Click()
Dim objRootKey As RegKey
Dim objStartKey As RegKey
Dim objValue As RegValue
Dim iNumber As Integer
Dim iRetNumber As Integer
    
Const stSubRoot1 As String = "Software\Microsoft\Office\10.0\Excel\Options"
Const stAddin As String = "C:\DDE\Test.xla"

'The predefined root-key.
Set objRootKey = RegKeyFromHKey(HKEY_CURRENT_USER)

'Parse the subkey.
Set objStartKey = objRootKey.ParseKeyName(stSubRoot1)

iNumber = 0

'Retrieve the highest OPEN-number.
For Each objValue In objStartKey.Values
    If objValue.Name Like "OPEN*" Then
        iRetNumber = CInt(Val(StrReverse(objValue.Name)))
        If iRetNumber > iNumber Then iNumber = iRetNumber
    End If
Next objValue

'Add the value to the subkey.
objStartKey.Values.Add "OPEN" & iNumber + 1, """" & stAddin & """", RegValueType.rvString

'Release objects from memory.
Set objValue = Nothing
Set objStartKey = Nothing
Set objRootKey = Nothing

End Sub

All comments & feedback are most welcome.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,215,833
Messages
6,127,157
Members
449,367
Latest member
w88mp

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top