AddAt Method [Visio 2003 SDK Documentation]
Creates a new object at a specified index in a collection.
objRet = object**.AddAt**(index)
objRet The new object added to the collection.
object Required. An expression that returns an object in the Applies to list.
index Required Long. The index at which to add the object.
Version added
4.0
Remarks
If the index is zero (0), the object is added at the beginning of the collection.
The beginning of a Menus collection is the leftmost menu when the menus are arranged horizontally. For example, the File menu is the first menu in the Menus collection for the drawing window context.
The beginning of a MenuItems collection is the topmost menu item. For example, the New Window menu item is the first menu item in the MenuItems collection for the WindowMenu object.
The beginning of a ToolbarItems collection is the leftmost item in a toolbar that is arranged horizontally.
Example
The following macro shows how to add a menu and menu item to the drawing window menu set. This macro uses the AddAt method to add a menu before the Microsoft Office Visio Window menu.
This example assumes that you already have a macro called "MyMacro" in the Microsoft Visual Basic for Applications (VBA) project associated with the active Visio document.
Public Sub AddAt_Example()
Dim vsoUI 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 UI object that represents Microsoft Office Visio built-in menus.
Set vsoUI = Visio.Application.BuiltInMenus
'Get the MenuSets collection.
Set vsoMenuSets = vsoUI.MenuSets
'Get the drawing window menu set.
Set vsoMenuSet = vsoMenuSets.ItemAtID(visUIObjSetDrawing)
'Get the Menus collection.
Set vsoMenus = vsoMenuSet.Menus
'Add a Demo menu before the Window menu.
Set vsoMenu = vsoMenus.AddAt(7)
vsoMenu.Caption = "Demo"
'Get the MenuItems collection.
Set vsoMenuItems = vsoMenu.MenuItems
'Add a menu item to the new Demo menu.
Set vsoMenuItem = vsoMenuItems.Add
'Set the properties for the new menu item.
vsoMenuItem.Caption = "Run &MyMacro"
vsoMenuItem.AddOnName = "ThisDocument.MyMacro"
vsoMenuItem.ActionText = "Run MyMacro"
'Tell Visio to use the new UI when the document is active.
ThisDocument.SetCustomMenus vsoUI
End Sub
Applies to | MenuItems collection | Menus collection | ToolbarItems collection | Toolbars collection
See Also | AddAtID method