Monday, June 18, 2007

Excel VBA - install an Excel Add-in (XLA or XLL)

Adding Addins Automatically using VBA


Most of today's Excel VBA code are as Addins (XLA or XLL). As an organization progresses there comes many revisions for the Addin - hence the need to update the program.

Here is a simple way to add a new addin:

Sub Add_an_Addin()

Dim oAddin As AddIn
Dim oTempBk As Workbook


Set oTempBk = Workbooks.Add

Set oAddin = AddIns.Add("E:\CostBenefit1.0.xla", True)
oAddin.Installed = True

oTempBk.Close

End Sub


If you wonder why a temporary workbooks is added - it is because to avoid the Run-time error '1004': Unable to get the Add property of the AddIns class or Run-time error '1004': Add method of addins class failed exceptions that are raised when there are no workbooks. Just be safe!!

7 comments:

  1. Anonymous7:03 AM

    i have a file that i use in my old computer, now have a windows xp with office 2007 the file is xla. file but when i instaled it excel could not fin it , can you tell me how to install it???

    ReplyDelete
  2. Did you mean that the Commandbars/Menu bar is not loaded?

    ReplyDelete
  3. I don't think you defined oXL in your code.

    ReplyDelete
  4. Thanks Robb.

    The code could execute without oXL. I have modified it accordingly

    ReplyDelete
  5. Hi our application written in vb, report writer is crystal report, using SQL 2005, I am looking solution how to open excel from my application directly, how do I do the add in ?

    Any expert here ?

    ReplyDelete
  6. In Visual Basic you need to add a reference to Microsoft Excel Object Library and then use the following code

    Set oXL = New Excel.Application
    oXL.Visible = True

    ReplyDelete
  7. Keith7:35 AM

    What do you do when you have added the Addin, it shows up in your Addin list, but it fails when you try to set Installed = True. I can get it to work on my computer and one other, but some computers it fails on. I've messed around with all of the security settings, set them the same as what is working to see if one of them might be preventing it and it still fails.

    ReplyDelete

StumbleUpon
Share on Facebook
Related Posts Plugin for WordPress, Blogger...
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.