Changing the Excel Command Bar

Case250

Board Regular
Joined
Oct 4, 2006
Messages
54
Hi everyone.
I am trying to add a menu item to another menu item.


Example: I have added a menu called "Product" to the Worksheet command bar between the "Window" and "Help" menus. Within this new "Product" menu I have added a menu item called "Export" by doing as follows:

Set Item = CommandBars(1).Controls("Product").Controls.Add
Item.Caption = "&Export"
Item.OnAction = "ExportMacro"

Now I want to add additional menu items so that they appear or becom availiable when the user moves the hovers the mouse cursor over the "Export" menu item. To see what I am wanting to do; in Excel go "File" then "Print View". When you hover the cursor over "Print View" it reveals several other menu item options. How do I do this?
Thanks
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Good afternoon Case250

Use something like this. I can't tailor this code any closer to your own project as you haven't posted the code you've used.

Code:
Sub Test()
Dim NewMenu As CommandBarPopup, MenuItem As CommandBarControl, Submenuitem As CommandBarButton
Set NewMenu = CommandBars(1).Controls.Add(Type:=msoControlPopup, temporary:=True)
NewMenu.Caption = "My Menu"
Set MenuItem = NewMenu.Controls.Add(Type:=msoControlPopup)
MenuItem.Caption = "My Menu Item"
Set Submenuitem = MenuItem.Controls.Add(Type:=msoControlButton)
Submenuitem.Caption = "My Sub Menu Item"
End Sub

HTH

DominicB
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,443
Members
448,898
Latest member
drewmorgan128

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