Kiwiman
Registered User
- Local time
- Today, 17:15
- Joined
- Apr 27, 2008
- Messages
- 799
Howzit
I have a problem trying to add an Addin to an Addin ribbon, but the code will not remove the existing button first - so I end up with multiple buttons on the ribbon doing the same thing. I therefore have to manually delete these buttons.
This is the code I have in the "ThisWorkbook" section. I'm not sure why this does not delete the existing button.
Any ideas?
I have a problem trying to add an Addin to an Addin ribbon, but the code will not remove the existing button first - so I end up with multiple buttons on the ribbon doing the same thing. I therefore have to manually delete these buttons.
This is the code I have in the "ThisWorkbook" section. I'm not sure why this does not delete the existing button.
Any ideas?
Code:
Option Explicit
Dim cControl As CommandBarButton
Const cMenu As String = "MultiTab CSV"
Private Sub Workbook_AddinInstall()
On Error Resume Next 'Just in case
'Delete any existing menu item that may have been left.
Application.CommandBars("Worksheet Menu Bar").Controls.Delete
'Add the new menu item and Set a CommandBarButton Variable to it
Set cControl = Application.CommandBars("Worksheet Menu Bar").Controls.Add
'Work with the Variable
With cControl
.Caption = "Save MultiTab Workbook as a series of CSV files"
.Style = msoButtonCaption
.OnAction = "SaveMultiSheetWorkbookAsCSVFiles"
'Macro stored in a Standard Module
End With
Set cControl = Application.CommandBars("Worksheet Menu Bar").Controls.Add
On Error GoTo 0
End Sub
Private Sub Workbook_AddinUninstall()
On Error Resume Next 'In case it has already gone.
Application.CommandBars("Worksheet Menu Bar").Controls(cMenu).Delete
On Error GoTo 0
End Sub