Excel Addin Install via Registry
Below is a slightly different approach (still a vbScript as opposed to a VBA
subroutine) where I use the "Excel.Application" object to not only determine
the version of Excel installed but to also confirm that the add-in to be
installed is present in the appropriate location on the PC and that it isn't
already installed rather than checking those things reading the registry
with WMI.
The first line of the script needs to be edited to the file name of your
add-in. If the add-in is located and if it isn't already installed, the
script uses WMI to write the new registry value and the add-in gets
installed.
Steve Yandl
_____________________________
strAddIn = "CleanHyper.xla"
' Make sure the add in is present in the file system
' Check if it is currently installed or not
' Check the version number of Excel on this PC
Set objXL = CreateObject("Excel.Application")
bExists = False
bInstalled = False
intAtotal = 0
If objXL.AddIns.Count 0 Then
For a = 1 To objXL.AddIns.Count
If objXL.AddIns(a).Name = strAddIn Then
bExists = True
If objXL.AddIns(a).Installed Then
bInstalled = True
End If
End If
' Count total installed add-ins
If objXL.AddIns(a).Installed Then
intAtotal = intAtotal + 1
End If
Next
End If
strVersion = objXL.Version
Set objXL = Nothing
' Exit script if add-in file isn't available on this PC
If Not bExists Then
MsgBox strAddIn & " wasn't available on this PC"
WScript.Quit
End If
' Exit script if add-in is already installed
If bInstalled Then
WScript.Quit
End If
' Made it this far, install the add-in
If intAtotal = 0 Then
strValName = "OPEN"
Else
strValName = "OPEN" & CStr(intAtotal)
End If
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
On Error Resume Next
Set objRegistry = GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Office\" _
& strVersion & "\Excel\Options"
objRegistry.SetStringValue HKEY_CURRENT_USER, strKeyPath, _
strValName, strAddIn
|