Hi all
I've pinched some code from a previous thread which creates a custom toolbar when I open a workbook
It works OK but I would like to tweak a couple of things, so any idea on how I do the following
1. At present the tool bar opens in the middle of the worksheet, how do I get it to 'dock' in the toolbar area at the top of the screen
2. To run the macro that's inside the toolbar I have to click on the tool bar to activate a dropdown list and then click the (only) button. How can I get the button moved up a level so that it's directly accessible from the toolbar (ie I don't have to to do the dropdown bit)
Thanks
Jim
Private Sub CreateMyCommandBar()
Dim ocb As CommandBarControl
Dim cbr As CommandBar
Dim objCommandBarButton As CommandBarButton
'reset/delete a previous custom menu before create a new custom menu
Call DeleteMyCommandBar
Set cbr = Application.CommandBars.Add("MyMenu")
Set ocb = cbr.Controls.Add(Type:=msoControlPopup, Temporary:=True)
ocb.Caption = "&My Menu"
'add a ControlButton to a commandbar
Set objCommandBarButton = ocb.Controls.Add(Type:=msoControlButton, ID:=1)
With objCommandBarButton
.Caption = "MyMenu"
.OnAction = "tabmenu"
.Style = msoButtonIconAndCaption
.FaceId = 2892
.BeginGroup = False
End With
Set ocb = Nothing
Set objCommandBarButton = Nothing
Application.CommandBars("MyMenu").Visible = True
End Sub
I've pinched some code from a previous thread which creates a custom toolbar when I open a workbook
It works OK but I would like to tweak a couple of things, so any idea on how I do the following
1. At present the tool bar opens in the middle of the worksheet, how do I get it to 'dock' in the toolbar area at the top of the screen
2. To run the macro that's inside the toolbar I have to click on the tool bar to activate a dropdown list and then click the (only) button. How can I get the button moved up a level so that it's directly accessible from the toolbar (ie I don't have to to do the dropdown bit)
Thanks
Jim
Private Sub CreateMyCommandBar()
Dim ocb As CommandBarControl
Dim cbr As CommandBar
Dim objCommandBarButton As CommandBarButton
'reset/delete a previous custom menu before create a new custom menu
Call DeleteMyCommandBar
Set cbr = Application.CommandBars.Add("MyMenu")
Set ocb = cbr.Controls.Add(Type:=msoControlPopup, Temporary:=True)
ocb.Caption = "&My Menu"
'add a ControlButton to a commandbar
Set objCommandBarButton = ocb.Controls.Add(Type:=msoControlButton, ID:=1)
With objCommandBarButton
.Caption = "MyMenu"
.OnAction = "tabmenu"
.Style = msoButtonIconAndCaption
.FaceId = 2892
.BeginGroup = False
End With
Set ocb = Nothing
Set objCommandBarButton = Nothing
Application.CommandBars("MyMenu").Visible = True
End Sub