PDA

View Full Version : Add-In Buttons Delete When Excel Closes



k1121
09-16-2020, 07:54 AM
I created an Excel Add-In that contains several macros. I added the following code to "ThisWorkbook" within the .xlam file. I am able to activate the add-in via the "Excel Add-Ins" button on the developer tab. When I close the workbook and open it back up, the add-in is still activated via the "Excel Add-Ins" button but the macro buttons no longer appear on the "Add-ins" tab. I have a similar add-in also. If I install the second add-in after the first then only the macro buttons from the second add-in are deleted and the buttons from the first add-in remain. If I add a third add-in then the buttons from the first two remain while the buttons from the third get deleted, etc. It seems like Excel is basically undoing the last action that happened before I closed Excel. I tried removing the Private Sub Workbook_AddinUninstall() section of the code but that didn't solve it.

Any idea why this is happening?

Code to create the buttons on the "Add-ins" tab.

Private Sub Workbook_AddinInstall()
With Application.CommandBars("Standard").Controls.Add
.Caption = "Save New Version"
.FaceId = 3
.Style = msoButtonIconAndCaptionBelow
.OnAction = "Version_Save"
End With
With Application.CommandBars("Standard").Controls.Add
.Caption = "Create Delivery Workbook"
.FaceId = 263
.Style = msoButtonIconAndCaptionBelow
.OnAction = "DeliveryWorkbook"
End With
End Sub
Private Sub Workbook_AddinInstall()
With Application.CommandBars("Standard").Controls.Add
.Caption = "Save New Version"
.FaceId = 3
.Style = msoButtonIconAndCaptionBelow
.OnAction = "Version_Save"
End With
With Application.CommandBars("Standard").Controls.Add
.Caption = "Create Delivery Workbook"
.FaceId = 263
.Style = msoButtonIconAndCaptionBelow
.OnAction = "DeliveryWorkbook"
End With
End Sub

Code to delete the buttons on the "Add-ins" tab when uninstalling.

Private Sub Workbook_AddinUninstall()
On Error Resume Next
Application.CommandBars("Standard").Controls("Save New Version").Delete
Application.CommandBars("Standard").Controls("Create Delivery Workbook").Delete
On Error GoTo 0
End Sub