How can i assign macros to multiple buttons in excel?
I have a code where i create a toolbar, add a button and assign macro to it, but when i add a second button macro is being assigned to the first button instead of the second.
Dim cbar1, myBar
'
Set cbar1 = CommandBars.Add(Name:="Future Tranx", Position:=msoBarBottom)
cbar1.Visible = True
Set myBar = CommandBars("Future Tranx")
Application.CommandBars("Future Tranx").Controls.Add Type:=msoControlButton, _
ID:=988, Before:=1
Set cbar1 = myBar.Controls(myBar.Controls.Count)
cbar1.Caption = "&Generate Commission Totals"
myBar.Controls("&Generate Commission Totals").Style = msoButtonIconAndCaption
cbar1.BeginGroup = True
cbar1.OnAction = "InsertCommTotals"
Application.CommandBars("Future Tranx").Controls.Add Type:=msoControlButton, _
ID:=455, Before:=2
------does not work------
'cbar1.Caption = "&Update File"
' myBar.Controls("&Update File").Style = msoButtonIconAndCaption
'myBar.BeginGroup = True
'cbar1.OnAction = "Sheet_SaveAs_Date"
Thanks
I have a code where i create a toolbar, add a button and assign macro to it, but when i add a second button macro is being assigned to the first button instead of the second.
Dim cbar1, myBar
'
Set cbar1 = CommandBars.Add(Name:="Future Tranx", Position:=msoBarBottom)
cbar1.Visible = True
Set myBar = CommandBars("Future Tranx")
Application.CommandBars("Future Tranx").Controls.Add Type:=msoControlButton, _
ID:=988, Before:=1
Set cbar1 = myBar.Controls(myBar.Controls.Count)
cbar1.Caption = "&Generate Commission Totals"
myBar.Controls("&Generate Commission Totals").Style = msoButtonIconAndCaption
cbar1.BeginGroup = True
cbar1.OnAction = "InsertCommTotals"
Application.CommandBars("Future Tranx").Controls.Add Type:=msoControlButton, _
ID:=455, Before:=2
------does not work------
'cbar1.Caption = "&Update File"
' myBar.Controls("&Update File").Style = msoButtonIconAndCaption
'myBar.BeginGroup = True
'cbar1.OnAction = "Sheet_SaveAs_Date"
Thanks