AddOnName Property [Visio 2003 SDK Documentation]
Gets or sets the name of an add-on or procedure that is run when its associated menu item, toolbar button, or accelerator key is selected.
object**.AddOnName** = string
string = object**.AddOnName**
object Required. An expression that returns an object in the Applies to list.
string Required String. The name of the add-on in the Addons collection, or a procedure in a Microsoft Visual Basic for Applications (VBA) project.
Version added
4.0
Remarks
If the project of the currently active document (or another project if it is referenced) does not have a procedure named string, or if the arguments passed in string do not match those specified in the procedure, Microsoft Office Visio runs the add-on named string. If no add-on named string can be found, Visio does nothing and reports no error. (You can use the TraceFlags property to monitor the procedures and add-ons that Visio attempts to run.)
If string is an add-on, use the AddOnArgs property to specify arguments to send to the add-on when it is run.
If string is a procedure, specify arguments using procname(arguments) or procname arguments.
When calling a procedure in a standard module it is recommended that you prefix the string with the module name that contains the procedure (for example, moduleName.procName) because more than one module can have a procedure with the same name.
To call a procedure in a project other than the project of the active document, use the syntax projName.modName.procName (you must have explicitly set a reference to projName in your Visual Basic project).
If the AddOnName property is set, Visio ignores the object's CmdNum property.
Note Beginning with Visio 2002, the AddOnName property cannot execute a string that contains arbitrary VBA code. To call code that in previous versions of Visio you would have passed to the AddOnName property, move the code to a procedure in a document's VBA project that is called from the AddOnName property.
Example
This VBA macro shows how to set the AddOnName property of a menu item. It also shows how to add a menu and menu item to the drawing window menu set, and how to set some of the menu item's other properties, such as Caption, AddOnArgs, and ActionText.
This example assumes that you already have a macro named "macroname" in the project of the active document, and that the macro takes an argument called "Arg1." Before running this example, replace ("macroname") with the name of your macro.
To restore the built-in menus in Microsoft Office Visio after you run this macro, call the ThisDocument.ClearCustomMenus method.
Public Sub AddOnName_Example()
Dim vsoUIObject As Visio.UIObject
Dim vsoMenuSet s 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 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 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 &("macroname")"
vsoMenuItem.AddOnName = "This Document.("macroname")"
vsoMenuItem.AddOnArgs = "/Arg1 = True"
vsoMenuItem.ActionText = "Run ("macroname")"
'Tell Visio to use the new UI when the document is active
ThisDocument.SetCustomMenus vsoUIObject
End Sub
Applies to | AccelItem object | Menu object | MenuItem object | ToolbarItem object
See Also | AddOnArgs property | Addons collection | CmdNum property | ExecuteLine method | ParseLine method | TraceFlags property