Dynamically Create a tool bar in Excel VBA
In Excel the tool bar button is used to call the xla file, for that i written a code to create the tool bar dynamicallyno need to add the xla file manually in to the workbook.Place the code in the one seperate module, the code is written in the "Auto_Open" event of excel workbook,the below code will create a tool bor with two buttons.Take a look at that and try it once,
'--------------------------------------------------------------------
Public Sub Auto_Open()
Dim cm As Office.CommandBar
On Error Resume Next
'Delete the toolbar if it already exists
Application.CommandBars("NewToolBar").delete
On Error GoTo 0
'Create the new toolbar each time this workbook opens
Set cm = Application.CommandBars.Add("NewToolBar", , , Temporary:=True)
With cm.Controls
'Add a button to the tool bar
With .Add(msoControlButton)
.Caption = "New Button"
'While click the button in the tool bar
'the method name entered here will called
.OnAction = "EntertheMethodName"
.FaceId = 1763
.Style = msoButtonIcon
End With
'Can add more than one button in the same tool bar
With .Add(msoControlButton)
.Caption = "New Button1"
'While click the button in the tool bar
'the method name entered here will called
.OnAction = "EntertheMethodName1"
.FaceId = 2882
.Style = msoButtonIcon
End With
End With
cm.Position = msoBarTop
cm.Visible = True
End Sub
'--------------------------------------------------------------------
Cheers........