Erich,
This is from a small
VB app which does just what you are after. I think the
problem might be that you have to have a workbook open in order to install
an add-in. Don't ask why. The use of app.path below is possible because this
program is installed to the same folder as the add-in itself. Try running
your Excel version with no workbook open to see if you get the error.
Private Sub Form_Load()
Dim oAddin As Object
Dim oXL As Object
Set oXL = CreateObject("Excel.Application")
Dim strPath As String
oXL.Workbooks.Add
strPath = App.Path & "\XspandXL.xla"
Set oAddin = oXL.ADDINS.Add(strPath)
oAddin.installed = True
oXL.Quit
Set oXL = Nothing
Unload Me
Call MsgBox("XspandXL should launch automatically the next time that you
restart Excel", _
vbOKOnly, "XspandXL")
End Sub
HTH,
Robin Hammond
www.enhanceddatasystems.com
"Erich Neuwirth" wrote in message
...
The following code works
Sub Test1()
On Error Resume Next
AddIns.Add ( _
"C:\Documents and Settings\neuwirth\My Documents\MyTestAddin.xla")
If Err.Number < 0 Then
MsgBox Err.Number & " " & Err.Description
End If
AddIns("Mytestaddin").Installed = True
End Sub
The following code does NOT work, it breaks with Error 1004
Add method of Addins class failed
Sub Test2()
On Error Resume Next
Dim objExcelApp As Excel.Application
Set objExcelApp = New Excel.Application
objExcelApp.AddIns.Add _
"C:\Documents and Settings\neuwirth\My Documents\MyTestAddin.xla"
If Err.Number < 0 Then
MsgBox Err.Number & " " & Err.Description
End If
objExcelApp.AddIns("Mytestaddin").Installed = True
End Sub
Since I ultimately want to turn Test2 into a standalone VB application,
I need to know why it fails.
Is there a way of making it work?
When I try to run Test2 from Word
(with Excel not running) I get the same error.