Addin installation

E

Erich Neuwirth

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.
 
R

Robin Hammond

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
 
E

Erich Neuwirth

This did the trick,
I only added
oXL.DisplayAlerts = False

to avoide the save file dialiog when closing Excel.
I also founf the following link
http://www.codeguru.com/vb/gen/vb_misc/tips/article.php/c2735/
very useful, it allows to use command line parameters,
so one can write a generic installer which takes the name
of the addin to be installed from the command line.

Now I would like to know:
Is there a similar way to UNINSTALL an addin?

oXL.ADDINS.REMOVE(strPath)
does not exist.
oAddin.installed = False works.
Just deleting the addin file, however,
will produce an error when the
Addin dialog is opened from Excel.
 
K

keepITcool

I've got a VB6 routine that just reads and manipulates the various
registry keys, saves you plenty of hassle.. PLUS it installs for every
version of excel installed on the system ..Does remove too :)

The only drawback it that excel must be closed.
if interested please mail.


--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Erich Neuwirth wrote :
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top