I am having troubles with custom menu items in Visio 2002
Professional SR-1 on Windows 2000 SP2 (though I have
tested on other PCs).
It seems possible to add a menu item that calls a custom
Document method, but not one that calls a built-in
Document method.
For example, the following works (provided the
ThisDocument.Hello sub exists);
oMenuItem.AddonName = "ThisDocument.Hello(""world"")"
But this doesn't (the item is disabled);
oMenuItem.AddonName = "ThisDocument.Close"
Note: I know there are other ways to trigger a document
close, this example applies to other built-in methods and
to ExecuteLine in particular.
Both of these menu items would show as enabled (and
function correctly) within Visio 200.
Has anyone had the same problem? Have I a setting amiss?
Is there an alternative way of calling
ThisDocument.ExecuteLine() from a menu item in Visio 2002?
or, is this a new "feature"? For what it's worth, I'll
acknowledge anyone with a good answer in my source code
(in ALL CAPS if preferred)!
Thank you,
Tim.
-----------------------------------------------------------
'Macros that work under Visio 2000 but not Visio 2002 SR-1
Sub hello(Optional planet As String = "Hello")
MsgBox "Hello " & planet
End Sub
Public Sub AddMenu()
Dim oUI As Visio.UIObject
Dim oMenus As Visio.Menus
Dim oMenu As Visio.Menu
Dim oMenuItem As Visio.MenuItem
Set oUI = Visio.Application.BuiltInMenus
Set oMenus = oUI.MenuSets.ItemAtID
(visUIObjSetDrawing).Menus
'Add a new menu before Window menu
Set oMenu = oMenus.AddAt(7)
oMenu.Caption = "Test Menu"
'Add items to the new menu
Set oMenuItem = oMenu.MenuItems.AddAt(0)
oMenuItem.Caption = "ThisDocument.Hello(""world"")"
oMenuItem.AddOnName = "ThisDocument.Hello(""world"")"
Set oMenuItem = oMenu.MenuItems.AddAt(0)
oMenuItem.Caption = "ThisDocument.close"
oMenuItem.AddOnName = "ThisDocument.close"
Set oMenuItem = oMenu.MenuItems.AddAt(0)
oMenuItem.Caption = "ThisDocument.ExecuteLine
(""ThisDocument.Hello"")"
oMenuItem.AddOnName = "ThisDocument.ExecuteLine
(""ThisDocument.Hello"")"
Visio.Application.SetCustomMenus oUI
End Sub
The following article explains the changes that were made to the AddOnName
property for Visio 2002:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvisio02/html/vis_runadd.asp
--
Dawn
This posting is provided "AS IS" with no warranties, and confers no rights.
"Timothy Bourke" <tbo...@csc.com.au> wrote in message
news:05d301c33468$c5e26ea0$a401...@phx.gbl...
> I am having troubles with custom menu items in Visio 2002
> Professional SR-1 on Windows 2000 SP2 (though I have
> tested on other PCs).
>
> It seems possible to add a menu item that calls a custom
> Document method, but not one that calls a built-in
> Document method.
>
> For example, the following works (provided the
> ThisDocument.Hello sub exists);
> oMenuItem.AddonName = "ThisDocument.Hello(""world"")"
> But this doesn't (the item is disabled);
> oMenuItem.AddonName = "ThisDocument.Close"
> Note: I know there are other ways to trigger a document
> close, this example applies to other built-in methods and
> to ExecuteLine in particular.
>
> Both of these menu items would show as enabled (and
> function correctly) within Visio 200.
> ...
I don't know how I overlooked this article in my initial
searches. I'm grateful for your link.
Tim.
Whilst this forum may not be specifically for Product
Feedback...
This new behaviour complicates things. I have worked
around it by sinking open and create events from my
stencil and programatically adding a reference to the
project for each document. Apparently this will work so
long as a System Administrator does not ``block access to
the VBA object model''. It seems this case can be avoided
by implementing a VSL (C++) `menu redirector'.
But, given my stencil is installed at the same path as any
VSL would be, and that the user will have chosen (one way
or another) to enable its macros, it seems hard to justify
all this extra work (and the risk for new bugs) on the
basis of increased security. Also, the Visio 2002 help
files for the AddOnName property are currently misleading.
>.
>