Add-In Automation Fails in Excel 2000

J

jean grey

Hi, everyone. I need some help why the ff. code does not succeed:

Public Sub InstallAddIn()

Dim xlApp, xlAddIn

Set xlApp = CreateObject ("Excel.Application")
xlApp.Workbooks.Add
xlAddIn = xlApp.AddIns.Add("C:\XXX.xla", True)
If Err.Number = 0 Then
xlAddIn.Installed = True
End If
xlApp.Quit
Set xlApp = Nothing

End Sub

This installs the add-in in Excel 2003 but not in Excel 2000.
It generates an error when calling xlAddIn = xlApp.AddIns.Add("C:\XXX.xla",
True)

I don't know how to modify the code using the suggested link below from
other forums:

http://support.microsoft.com/kb/213489/

Thanks in advance.
 
P

Peter T

That code should work fine even, in Excel-97.

Are you sure the path and name is correct, and if so the addin does not
already exist in the addins collection.

Regards,
Peter T
 
P

Peter T

Ah, I missed a typo in your code.

changeto
Set xlAddIn = xlApp.AddIns.Add("C:\XXX.xla", True)

With that typo the code would fail in any version.

As written the code should not be in Excel, eg Word. Ensure no instances of
Excel are open before running the code.

Regards,
Peter T
 
D

Dave Peterson

And wouldn't you want to avoid the possible error:

Option Explicit
Public Sub InstallAddIn()

Dim xlApp As Application 'As Object
Dim xlAddIn As AddIn 'as Object

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True 'for testing

xlApp.Workbooks.Add

On Error Resume Next
Set xlAddIn = xlApp.AddIns.Add("C:\XXX.xla", True)
If Err.Number = 0 Then
xlAddIn.Installed = True
End If
On Error GoTo 0

xlApp.Quit
Set xlApp = Nothing

End Sub

If you're running this from excel, I'm not sure why you want to start a new
excel application, though.

But if you're running this from a VBS file (testing via excel???), then I broke
your declarations.
 
J

jean grey

Thanks, guys for your suggestions.
I'm running the code from an external vbscript which is used to
automatically add the Add-in in Excel's Add-In Manager (somehow like an
installer).
You were right at some point. There's nothing wrong with my code.
Aside from the XLA, which had no problem registering, I have an XLL file and
found out that it was the one that fails to register. I also noticed that the
add-in is registered when there is Visual Studio installed, but it fails
when there's none.
Does anyone here know which lib or dll from Visual Studio should be included
in the build path?

Thanks.
 
P

Peter T

Are you using the RegisterXLL function to register your XLL.

Not sure why you need Visual studio installed as you haven't given any
details. Also not sure what you are asking re build path.

Regards,
Peter T
 
J

jean grey

I found out the cause of the error. The path of the XLL file should be added
to the system's environment variables because the XLL file is using another
DLL located at the same folder.

Anyway, thanks guys. :)
 

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