Share via


MenuItem.MenuItems Property

Visio Automation Reference

Returns the MenuItems collection of an object. Read-only.

Version Information
 Version Added:  Visio 4.0

Syntax

expression.MenuItems

expression   A variable that represents a MenuItem object.

Return Value
MenuItems

Remarks

If a Menu object represents a hierarchical menu, its MenuItems collection contains submenu items. Otherwise, its MenuItems collection is empty.

Example

This Microsoft Visual Basic for Applications (VBA) macro shows how to use the MenuItems property to get the MenuItems collection of a Menu object. It adds a menu and menu item to the drawing window menu set and sets the menu and menu item's Caption properties.

To restore the built-in menus in Microsoft Office Visio after you run this macro, call the ThisDocument.ClearCustomMenus method.

Visual Basic for Applications
  Public Sub MenuItems_Example()
 
    Dim vsoUIObject As Visio.UIObject 
    Dim vsoMenuSets As Visio.MenuSets 
    Dim vsoMenuSet As Visio.MenuSet   
    Dim vsoMenus As Visio.Menus 
    Dim vsoMenu As Visio.Menu 
    Dim vsoMenuItems As Visio.MenuItems 
    Dim vsoMenuItem As Visio.MenuItem 
'Get a UIObject object that represents Microsoft Office Visio built-in menus.
Set vsoUIObject = Visio.Application.BuiltInMenus 

'Get the MenuSets collection.
Set vsoMenuSets = vsoUIObject.MenuSets 

'Get the drawing window menu set. 
Set vsoMenuSet = vsoMenuSets.ItemAtID(visUIObjSetDrawing) 

'Get the Menus collection. 
Set vsoMenus = vsoMenuSet.Menus 

'Add a new menu before the Window menu.
Set vsoMenu = vsoMenus.AddAt(7) 
vsoMenu.Caption = "MyNewMenu" 

'Get the MenuItems collection.
Set vsoMenuItems = vsoMenu.MenuItems 

'Add a menu item to the new menu.
Set vsoMenuItem = vsoMenuItems.Add 

'Set the Caption property for the new menu item. 
vsoMenuItem.Caption = "&MyNewMenuItem" 

'Tell Visio to use the new UI when the document is active. 
ThisDocument.SetCustomMenus vsoUIObject 

End Sub

See Also