When you create Excel Addins and distribute them to a lot of users, normally the users must copy the Add-in files into the “Addins” folder from the path: “C:Usersuser_nameAppDataRoamingMicrosoftAddIns” and after that to activate the Addin from Excel:
Because these steps take time, the users must follow them everytime when you send a new version of the Addin and sometimes they forget what to do, I created a VBA code which installs and activates automatically a specified Addin file.
How it works ?
- Create a new folder with the INSTALL.xlsm file (which can be downloaded at the end of this post) and your Addin.xlam file. (the files must be in the same folder !):
- Open the INSTALL.xlsm file and in the VBA Developer- Module1, install_add_in() procedure change the fileName variable assignment with the name of your addin file:
Sub install_add_in() Dim mypath As String, strfile As String, fileName As String mypath = ActiveWorkbook.Path fileName = "General.Tools" 'replace General.Tools with the name of your Add-in !!! strfile = "" & fileName & ".xlam" file_to_copy = mypath & strfile folder_to_copy = Environ("Appdata") & "MicrosoftAddIns" copied_file = folder_to_copy & strfile 'Check if add-in is installed If Len(Dir(copied_file)) = 0 Then 'if add-in does not exist then copy the file FileCopy file_to_copy, copied_file AddIns(fileName).Installed = True MsgBox "Add-in installed" Else 'if add-in already exists then the user will decide if will replace it or not x = MsgBox("Add-in allready exists ! Replace ?", vbYesNo) If x = vbNo Then Exit Sub ElseIf x = vbYes Then 'deactivate the add-in if it is activated If AddIns(fileName).Installed = True Then AddIns(fileName).Installed = False End If 'delete the old file Kill copied_file 'copy the new file FileCopy file_to_copy, copied_file AddIns(fileName).Installed = True MsgBox "New Add-in Installed !" End If End If End Sub
- Save the file, create a *.zip/*.rar archive with the folder and send it to all users.
- The users will now Install and activate automatically the Addin by opening the INSTALL.xlsm file and just pressing the “INSTALL ADDIN” button.
- If an old version of the Addin already exists in the Addins folder, the user will be asked to confirm if he wants to replace it with the new file.
–> Using this code the users will not have to remember where to copy the files and how to activate the Addins.
Download the INSTALL.xlsm file:
Hello to every body, it’s my first go to see of this weblog;
this web site contains remarkable and in fact good stuff for readers.
Dear Team,
The code is very usefull.
Thank you so much!
Regards
M D SHIVARAM
This is exactly what I’m looking for. Simple but powerful.
Thank you so much!
GREAT!
Thank you so much!