menu .AddOnName won't run subroutine

G

goldnhue

My custom menu option loads whenever a Visio document loads, but I can't get
..AddOnName to run a procedure "MySub" that is located in a Module on the
Stencil. Any suggestions?

MenuItem.AddOnName = "MyModule.MySubroutine" <-- THIS DOES NOT WORK.

If needed, the complete menu setup code is below ... all else seems to work
fine.
Sub setmenu(ShpObj As Visio.shape)
' shpObj isn't used, just there to keep it from showing on the Macro menu
On Error GoTo ErrorTrap
Dim uiObj As Visio.UIObject
Dim menuSetsObj As Visio.MenuSets
Dim menuSetObj As Visio.MenuSet
Dim menusObj As Visio.Menus
Dim menuObj As Visio.Menu
Dim menuItemsObj As Visio.MenuItems
Dim menuItemObj As Visio.MenuItem
Dim deleting As Boolean

' Get a UI object copy of the built in Visio menus
Set uiObj = Visio.Application.BuiltInMenus
Set menuSetsObj = uiObj.MenuSets
' Get drawing window MenuSet Object
Set menuSetObj = menuSetsObj.ItemAtID(visUIObjSetDrawing)

'Get the Menus collection and add the PQMS menu to it at position 7
Set menusObj = menuSetObj.Menus
Set menuObj = menusObj.AddAt(7)
menuObj.Caption = "&Deva"

' Get the Menu Items collection and add the Deva menu option
Set menuItemsObj = menuObj.MenuItems
Set menuItemObj = menuItemsObj.Add
menuItemObj.Caption = "&Deva Menu"
menuItemObj.AddOnName = "MyModule.MySub" '<-- THIS DOESN'T WORK.

' Set the new menus.
Visio.Application.SetCustomMenus uiObj
' Tell Visio to use the new UI when the document is active.
ThisDocument.SetCustomMenus uiObj

Exit Sub
ErrorTrap:
End Sub
 
G

goldnhue

I tried all of the below, but the menu item is still greyd out. Is it
perhaps the way I'm referencing the sub? (the error is ususlly "can't find
method or data member")
NOTE: when I call this subroutine from a shape sheet event, this is what I
use:
CALLTHIS("PQMS.a_PQMS","Process_Model")

None of these menu calls work:
menuItemObj.AddOnName = ThisDocument.ExecuteLine(ThisDocument.PQMS.a_PQMS)
menuItemObj.AddOnName = ThisDocument.ExecuteLine("PQMS.a_PQMS")
menuItemObj.AddOnName = "ThisDocument.ExecuteLine(""a_PQMS"")"
menuItemObj.AddOnName = ExecuteLine("PQMS.a_PQMS")
menuItemObj.AddOnName = "ExecuteLine(""PQMS.a_PQMS"")"
menuItemObj.AddOnName = "ThisDocument.a_PQMS"
etc.

Any other thoughts?
 
D

David Parker

ThisDocument is a class, not a module.
You can't call functions in a class
 
G

goldnhue

Understood.
So what is the appropriate syntax to call a module that is located in the
stencil?

The Visio "AddOnName property" help example says it should be:
vsoMenuItem.AddOnName = "ThisDocument.("macroname")" ...Where
("macroname") is replaced with the macro ... I assume this is same for
procedure.

But whenever I surround the AddOnName string with "", it becomes inactive as
a selection in the menu.

Please advise.
 
J

Jacco

Are your macros in the document itself, or somewhere else? I have had
a similar problem, and needed to set a reference from the document you
want to use the macro in, to the document the macro actually is in. My
macros are in a stencil, and I need to set a reference to that stencil
from every document I want to use the macros in. (open de VBA editor,
select your document, then goto tools -> references and tick the box
in front of the document that your macros are in).

Hope that helps,

Jacco
 
G

goldnhue

Thank you for responding, Jacco!
My macro (Deva) is in a module (PQMS) that is located in the stencil
(Process_Model). I added the reference in the document as you suggested and
reloaded, but the menu option is still grayed out. Tried all kinds of syntax
to set the item as noted below, but nothing ... what would the correct
AddOnName syntax be in this situation?

menuItemObj.AddOnName = "ExecuteLine(""PQMS.Deva"")"
menuItemObj.AddOnName = "ThisDocument.Deva"
menuItemObj.AddOnName = "ThisDocument.Deva()"
menuItemObj.AddOnName = "Process_Model.Deva"
menuItemObj.AddOnName = "Deva"
etc.

Thanks in advance,
Gina
 
J

Jacco

Hi Gina,

This is the code that I use for calling macros in a stencil that is
referenced by the current document:

'Normal copypage
Set visMenuItem = visMenuItems.Add
visMenuItem.Caption = "&Copy Page"
visMenuItem.State = Visio.visButtonUp
visMenuItem.AddOnName = visStencilName + ".fd_utils.CopyPage"

In this example, visStencilName is a variable that contains the
stencil name, that should not be used in your case. Then, fd_utils is
the module and CopyPage the function.

I guess in your case, [menuItemObj.AddOnName = "PQMS.Deva" ] shoudl
work.

Good luck,
Jacco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top