It's much better to add your ToolBar within the code, there's many examples this is one I have edited from one of my existing workbooks.
Place this in a Standard Module, I have named the module mToolBars and it is added to the Data menu.
Option Explicit
'////////////////////////////////////////////////
'
'
' This module contains all code specific to the
' creation and deletion of the various buttons
' that are added to Excel's menus.'
'
'////////////////////////////////////////////////
Const APPNAME As String = "MyAddin"
Public Sub AddButtonsMain()
On Error GoTo errHandler
Call mToolbars.RemovesButtons
'Add a button to the Data menu.
AddButton Application.CommandBars("Data")
Exit Sub
errHandler:
MsgBox "Toolbar could not be created"
End Sub
Private Sub AddButton(ComBar As CommandBar)
'Adds the "JR Applications" button to the specified commandbar
Dim ComPop As CommandBarPopup, ComBut As CommandBarButton
Dim lngCurrentRow As Long
Dim lngLastRow As Long
On Error GoTo errHandler
Set ComPop = ComBar.Controls.Add(Type:=msoControlPopup, before:=1)
ComPop.BeginGroup = True
ComPop.Caption = APPNAME
Set ComBut = ComPop.Controls.Add(msoControlButton)
ComBut.BeginGroup = True
ComBut.Caption = "Load Form"
ComBut.OnAction = "ShowDataForm"
ComBut.Style = msoButtonIconAndCaption
ComBut.FaceId = 137
Exit Sub
errHandler:
MsgBox "The toolbar could not be added"
End Sub
Public Sub RemovesButtons()
Dim ComBar As CommandBar
Dim ComCtl As CommandBarControl
On Error GoTo errHandler
For Each ComCtl In Application.CommandBars("Data").Controls
If ComCtl.Caption = APPNAME Then ComCtl.Delete
Next ComCtl
Exit Sub
errHandler:
End Sub
This code is important to make sure that the ToolBar is loaded correctly & unloaded when not needed.
Option Explicit
Private Sub Workbook_AddinInstall()
Call mToolbars.AddButtonsMain
End Sub
Private Sub Workbook_AddinUninstall()
Call mToolbars.RemovesButtons
End Sub
Bookmarks