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!!
Monday, June 18, 2007
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.
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???
ReplyDeleteDid you mean that the Commandbars/Menu bar is not loaded?
ReplyDeleteI don't think you defined oXL in your code.
ReplyDeleteThanks Robb.
ReplyDeleteThe code could execute without oXL. I have modified it accordingly
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 ?
ReplyDeleteAny expert here ?
In Visual Basic you need to add a reference to Microsoft Excel Object Library and then use the following code
ReplyDeleteSet oXL = New Excel.Application
oXL.Visible = True
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.
ReplyDeleteAt the end of 2019, this post really helped me out. After hours of flailing about to get a one click install of an addin(.xlam), I finally landed here and was saved by the temp workbook idea. Thanks for sharing.
ReplyDelete