VBA Submenu and sort order

bsquad

Board Regular
Joined
Mar 15, 2016
Messages
194
I am wondering if the following code can somehow be altered so the Submenu is at the top or above 'Copy'

Code:
Sub Submenu()
    Dim Bar As CommandBar
    Dim NewMenu As CommandBarControl
    Dim NewSubmenu As CommandBarButton
    DeleteSubmenu
    Set Bar = CommandBars("Cell")
    Set NewMenu = Bar.Controls.Add(Type:=msoControlPopup, temporary:=True)
    NewMenu.Caption = "&Functions"
    NewMenu.BeginGroup = True
    Set NewSubmenu = NewMenu.Controls.Add(Type:=msoControlButton)
    With NewSubmenu
        .FaceId = 266
        .Caption = "I&mport"
        .OnAction = "CompAggregation"
    End With
    Set NewSubmenu = NewMenu.Controls.Add(Type:=msoControlButton)
    With NewSubmenu
        .FaceId = 254
        .Caption = "&Row Select"
        .OnAction = "Jump"
    End With


End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
When creating your new menu, you can use the Before argument to specify the position of the control on the command bar. Then you can set the BeginGroup property to True for the second control on the command bar.

Code:
Sub Submenu()
    Dim Bar As CommandBar
    Dim NewMenu As CommandBarControl
    Dim NewSubmenu As CommandBarButton
    DeleteSubmenu
    Set Bar = CommandBars("Cell")
    [COLOR=#ff0000]Set NewMenu = Bar.Controls.Add(Type:=msoControlPopup, [B]Before:=1[/B], temporary:=True)[/COLOR]
    NewMenu.Caption = "&Functions"
    [COLOR=#ff0000]Bar.Controls(2).BeginGroup = True[/COLOR]
    Set NewSubmenu = NewMenu.Controls.Add(Type:=msoControlButton)
    With NewSubmenu
        .FaceId = 266
        .Caption = "I&mport"
        .OnAction = "CompAggregation"
    End With
    Set NewSubmenu = NewMenu.Controls.Add(Type:=msoControlButton)
    With NewSubmenu
        .FaceId = 254
        .Caption = "&Row Select"
        .OnAction = "Jump"
    End With
End Sub
 
Upvote 0
Domenic,

thank you for the reply and a resolution; it working well.
>>I knew it was going to be something simple.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top