Reputation: 399
Sub Install_Addin()
Dim AI as excel.addin
Set AI = Application.Addins.Add("C:\Add_In.xlam")
AI.Installed = True
Application.Addins("Add_in").Installed = True
End Sub
Above is the code I got from Chip Pearson to install an Add-in to excel. This code works well for the first time. My add-in has a control button (I modifed the xml while writing the add-in) and so, when the add-in is installed (using the above code) a button automatically appears on my excel ribbon, and then I can use my add-in.
The problem is when I try re-installing my add-in. When I update the code of my add-in and try to re-install using the above code, I get this error ----
runtime error '1004'
Unable to copy add-in to library
This happens because the add-in is not properly uninstalled before it can be re-installed. And I have given up searching the web for a method to unistall an add-in using VBA code. I couldnt find any simple solution.
Right now the only way to un-install my add-in is to do it manually. First I delete the add-in from the Microsoft Add ins folder. Then I open Excel and it gives me a warning message that it could not find the add-in. Then I go to Add-in manager and click on my add-in and then click go. Then on the list of add-ins I tick my add-in and then excel says "Add-in not present. Delete from list?" and then the add-in is finally deleted.
Only after manually deletting the add-in like this, can I re-install my add-in using the above code. Now this is really cumbersome, especially when I want to distribute the add-in to other people. There has to be an easier way to update the add-in without having to first manually deleting it.
Please dont provide random answers or answers you think "might" be correct to this question. Also please dont tell me to "try out this and that". Only if you know the correct solution, tell me about it. I have already tried a number of things to no avail. :)
Thanks a lot.
Upvotes: 4
Views: 3221
Reputation: 23520
If you are changing the code in the XLAM but keeping its name and location the same you don't need to reinstall it as an addin.
If you want to uninstall an existing addin so that you can install a new version with a different name you can set the Installed property of the existing addin to False, but this leaves the existing addin in the list of available but not installed addins.
If you want to change the name or location of the addin a better solution is to use a stub addin loader to simplify reversioning and loading issues. You can download an open source working example from my website at http://www.decisionmodels.com/downloads.htm
Upvotes: 3