D
drewcogswell
I have placed all my macro code into a stencil file for easier
distribution. I can successfully run the macros through the Tools >
Macros > menus, but would like to be able to run them from a custom
menu. I have created the menu using the following code, but the items
are all disabled. It seems that it does not recognize the Sub names
in the stencil module as being in the global namespace.
The visMenuItem.AddOnName = "MyMacro" statement seems to be the
problem. If I reference a macro in a Module in the .vsd Document (not
the Stencil file), it works fine.
Does anybody have an example or know how to reference the stencil file
modules?
Dim uiObj As Visio.UIObject
Dim visMenuSets As Visio.MenuSets
Dim visMenuSet As Visio.MenuSet
Dim visMenus As Visio.Menus
Dim visMenu As Visio.Menu
Dim visMenuItems As Visio.MenuItems
Dim visMenuItem As Visio.MenuItem
Set uiObj = Visio.Application.BuiltInMenus
Set visMenuSets = uiObj.MenuSets
' Get the Visio object context menu set.
Set visMenuSet = visMenuSets.ItemAtID(visUIObjSetDrawing)
Set visMenus = visMenuSet.Menus
Set visMenu = visMenuSet.Menus.AddAt(7)
visMenu.Caption = "MyMacrosMenu"
' Get the items collection from the file menu
Set visMenuItems = visMenu.MenuItems
'Get macros menu from builtin menus
Dim toolsMenu As Visio.MenuItems
Dim macroMenu As Visio.MenuItem
Dim macroSubMenu As Visio.MenuItems
Dim documentMacros As Visio.MenuItem
Dim AddOnNameText As String
'ADD ITEMS
Set visMenuItem = visMenuItems.Add
visMenuItem.Caption = "MyMacro"
visMenuItem.State = Visio.visButtonUp
visMenuItem.AddOnName = "MyMacro"
visMenuItem.Enabled = True
' Set the new menus.
Visio.Application.ActiveDocument.SetCustomMenus uiObj
distribution. I can successfully run the macros through the Tools >
Macros > menus, but would like to be able to run them from a custom
menu. I have created the menu using the following code, but the items
are all disabled. It seems that it does not recognize the Sub names
in the stencil module as being in the global namespace.
The visMenuItem.AddOnName = "MyMacro" statement seems to be the
problem. If I reference a macro in a Module in the .vsd Document (not
the Stencil file), it works fine.
Does anybody have an example or know how to reference the stencil file
modules?
Dim uiObj As Visio.UIObject
Dim visMenuSets As Visio.MenuSets
Dim visMenuSet As Visio.MenuSet
Dim visMenus As Visio.Menus
Dim visMenu As Visio.Menu
Dim visMenuItems As Visio.MenuItems
Dim visMenuItem As Visio.MenuItem
Set uiObj = Visio.Application.BuiltInMenus
Set visMenuSets = uiObj.MenuSets
' Get the Visio object context menu set.
Set visMenuSet = visMenuSets.ItemAtID(visUIObjSetDrawing)
Set visMenus = visMenuSet.Menus
Set visMenu = visMenuSet.Menus.AddAt(7)
visMenu.Caption = "MyMacrosMenu"
' Get the items collection from the file menu
Set visMenuItems = visMenu.MenuItems
'Get macros menu from builtin menus
Dim toolsMenu As Visio.MenuItems
Dim macroMenu As Visio.MenuItem
Dim macroSubMenu As Visio.MenuItems
Dim documentMacros As Visio.MenuItem
Dim AddOnNameText As String
'ADD ITEMS
Set visMenuItem = visMenuItems.Add
visMenuItem.Caption = "MyMacro"
visMenuItem.State = Visio.visButtonUp
visMenuItem.AddOnName = "MyMacro"
visMenuItem.Enabled = True
' Set the new menus.
Visio.Application.ActiveDocument.SetCustomMenus uiObj