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.
All comments & feedback are most welcome.
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.