Installing Addin via Automation

A

Aragorn

I have an addin that I know functions correctly under normal
circumstances. If I manually add the addin via the excel UI, the
application addin installs correctly.

However, if I attempt to install the addin via automation, the
Workbook_AddinInstall method does not seem to run or at least does not
report errors back to the UI. I'm using the following code:

Dim oXL
Dim oAddin
Set oXL = CreateObject("Excel.Application")

oXL.Workbooks.Add
Set oAddin = oXL.AddIns.Add("C:\Program
Files\Company\Product\MacroFiles\Macro.xla")

oAddin.Installed = True

With this code the macro is automatically added in, but the
AddinInstall method clearly never runs or at least errors. For a
correct install I need this method to run. Any thoughts on this would
be greatly appreciated.
 
D

dominicb

Good evening Aragorn

Just a shot in the dark, Aragorn, but the code you're using isn't b
any chance saved as an add-in is it (ie, with no worksheet visible)?
If it is, then that's the problem. Excel likes to have a workshee
visible before it will allow a macro to start tinkering with the add-i
settings.

But if that's not the case then I don't know I'm afraid...

HTH

Dominic
 
A

Aragorn

dominicb,

I'm not quite sure what you mean, so I'll describe to you how I have it
set up. The vba project is saved as a .xla file. This xla contains a
VBA macro project with Sheet1, Sheet2, Sheet3, and ThisWorkBook as
objects. ThisWorkbook implements

Sub Workbook_AddinInstall()

The method adds several menu options and definitely runs when I manual
select it in excel. The script below never seems to result in the
AddinInstall method being run. I'm assuming that you're at least on
trace to some degree. I'm very new to all of this, so you're insite is
definitely helpful. Thanks.
 
P

Peter T

For me the AddinInstall event runs with your method.

Do you have any other instance of Excel open when you create your new
instance. If so, certain changes will only persist after closing the last
instance, and assuming changes were made in that instance.

Might be worth testing with GetObject (under On Error Resume Next) before
using CreateObject. This alone is not foolproof.

Regards,
Peter T



Aragorn said:
dominicb,

I'm not quite sure what you mean, so I'll describe to you how I have it
set up. The vba project is saved as a .xla file. This xla contains a
VBA macro project with Sheet1, Sheet2, Sheet3, and ThisWorkBook as
objects. ThisWorkbook implements

Sub Workbook_AddinInstall()

The method adds several menu options and definitely runs when I manual
select it in excel. The script below never seems to result in the
AddinInstall method being run. I'm assuming that you're at least on
trace to some degree. I'm very new to all of this, so you're insite is
definitely helpful. Thanks.
 
A

Aragorn

Peter,

I only expect that instance of excel to be open at install time, but
even another instance exists, I think it's reasonable that the user
won't expect excel to reflect its changes until excel has to be
reloaded in memory. That's all cool and isn't what I'm seeing.

How do you know for certain that the AddinInstall event is running. My
script does add the addin, it just doesn't add my menu items for me.
I'm assuming that you set up some dummy project. If so, can I see it.

Aaron

Peter said:
For me the AddinInstall event runs with your method.

Do you have any other instance of Excel open when you create your new
instance. If so, certain changes will only persist after closing the last
instance, and assuming changes were made in that instance.

Might be worth testing with GetObject (under On Error Resume Next) before
using CreateObject. This alone is not foolproof.

Regards,
Peter T
 
P

Peter T

Hi Aaron,
I only expect that instance of excel to be open at install time, but
even another instance exists, I think it's reasonable that the user
won't expect excel to reflect its changes until excel has to be
reloaded in memory. That's all cool and isn't what I'm seeing.

With two instances, try customizing your toolbar in one then close this
customized instance, then close the other one. Re-start Excel, no customized
toolbar - right. Similar for various other application settings.
How do you know for certain that the AddinInstall event is running. My
script does add the addin, it just doesn't add my menu items for me.
I'm assuming that you set up some dummy project. If so, can I see it.

In the "event of a test addin, I put

Debug.? "AddinInstall"

In the script (in a Word module) I added

oXl.Visible = true
Stop

looked in the xl's immediate window and there it was!

then back in Word I stepped through closing the instance and releasing
variables.

Regards,
Peter T
 

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