Hi all,
how can i create an extra menu in the menu-bar with vba-code? I have tried to record a macro and then do al the things necessary but if I run the code it doesn't create a proper menu.
MenuBars are one of VBA's Hidden Objects and are supported only for backward compatibility. To view hidden objects in the Object Browser, right-click in the Object Browser window and click Show Hidden Members on the shortcut menu.
The following code will add a MenuBar to the right of the HelpMenuItem and insert two items with a break between them.
Sub Menus()
With MenuBars("Worksheet"
.Reset
.Menus.Add ("&Menu"
With .Menus("&Menu"
.MenuItems.Add ("Macro&1", "Macro1"
.MenuItems.Add ("-"
.MenuItems.Add ("Macro&2", "Macro2"
End With
End With
End Sub
The & sets the ALT+Shorcut Key for that item. The "Macro1" and "Macro2" are the names of the macros to run when the MenuItem is selected. Please let me know if you have any questions.
when i try to execute the code, he doesn't seem to know
"MenuBars". I have right-clicked in the object browser and have clicked show hidden members and added the code but it doesn't work. What have I done wrong?
I apologize. My code was written in Excel VBA, and it won't transfer. I'm not familiar with Word VBA. I know that you will use the CommandBars("Menu Bar" object, but I'm not sure how to add items within the Menu Bar. If I find something, I'll let you know.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.