Roger,
try this.
Sub InstallAddIn()
'this is a VB routine that runs as part of an external installation package
to register an add-in with xl
'this was based on something I saw in the groups I think, but apoligies to
original author since I cannot remember who it was
Dim strApp As String
Dim strAddInPath As String
Dim oAddin As Object
Dim oXL As Object
Dim nExcelCount As Integer
strApp = App.Path
nExcelCount = 0
TestForExcel:
On Error Resume Next
Set oXL = GetObject(, "Excel.Application")
On Error GoTo 0
If Not (oXL Is Nothing) Then
If nExcelCount = 0 Then
Call MsgBox("Please save any files and quit Microsoft Excel then
press OK", _
vbOKOnly, msgTitle)
Else
Call MsgBox("You still have Excel running. To register this add-in
with Excel " & _
"you need to exit Excel first" & vbCrLf & vbCrLf & _
"If you can't see a running instance of Excel you may have a
hidden instance running" & vbCrLf & vbCrLf & _
"To close a hidden instance, press ALT-CTRL-DEL and remove Excel
from the list of running processes", _
vbOKOnly + vbInformation, msgTitle)
End If
nExcelCount = nExcelCount + 1
Set oXL = Nothing
GoTo TestForExcel
End If
Set oXL = CreateObject("Excel.Application")
'have to add a workbook or you can't add an add-in
oXL.Workbooks.Add
'never been happy with this line since the user could have changed the
default install path
'if you are running your own installer, you could make sure you trap the
right path
strAddInPath = Environ("ProgramFiles") & "\Enhanced
Datasystems\EFALoader.xla"
Set oAddin = oXL.Addins.Add(strAddInPath)
oAddin.installed = True
oXL.Quit
Set oXL = Nothing
Call MsgBox("Install complete", vbInformation + vbOKOnly, "Enhanced
Datasystems")
End Sub
Robin Hammond
www.enhanceddatasystems.com