Adding Menu Items with VBA using Stencils

R

Roy Baggies

I have some simple VBA macros that add a new Menu with menu items to Visio
programmatically. These autoload from Document_DocumentOpened() in
ThisDocument.

All works fine when the VBA macros / forms are included within a specific
Visio .vsd file. I'm now trying to put all the VBA code into a Stencil. I
have created a .vss file with everything in. I open an existing .vsd and then
use File->Shapes->Open Stencil to bring in my VBA macros. These autload and I
see my new Menu, but all Menu items are greyed out. Explicity setting
..enabled=true on the menu items makes no difference. Any ideas??
 
J

JuneTheSecond

Generally, in stencil, the key word ThisDocument should be replaced by
ActiveDocument,
For UiObject, it seems there is a bug in AddOnName property in Visio2003.
vsoMenuItem.AddOnName = "AnotherProject.Module1.test" does not work propery,
when you wish to run macro in another project.
There is not this kind of bug in On Action property in Commandbars object.
cbrMenuPopup.OnAction = "AnotherProject!test" works well.
So, if your code uses UiObject object, it may be an idea to replace into
CommandBars object.
 
G

Gerald K

This seems to be a bug. There are a few messages that already refer to this
over recent months (search on 'Menu').
One workaround I discovered was to call a Form that then calls the menu
creation routines. Not elegant, but seems to fix the problem.

Cheers, Gerald.
 
R

Roy Baggies

Many thanks for replies so far, starting to understand this. But I've tried
both approaches (calling from a form and using the CommandBars object and
still no joy.

When I use the CommandBars object I get similar errors to those already
posted in the thread. Works fine if I run the macros embedded in the Visio
file, but if I separate them out into a Stencil then I seem to lose context
with the OnAction method.

I have the following in my stencil module:

Sub AddMenuToMenuBar()
' Abstract - This procedure gets the active MenuBar from
' Visio and adds a Menu at the end

With Application.CommandBars.ActiveMenuBar.Controls
With .Add(Type:=msoControlPopup, before:=.Item("Window").Index,
temporary:=True)
.Caption = "Roy Utilities"
With .Controls.Add
.Caption = "Login Preferences"
.OnAction = ThisDocument.Name & "!ShowLoginDialog"
End With
End With
End With

I've tried ActiveDocument for OnAction as well as just 'ShowLoginDialog'
(also in my stencil module) but no luck .. if I delete OnAction the menu
shows up (and of course does nothing...)

Cheers
Roy
 
J

JuneTheSecond

In ".OnAction = ThisDocument.Name & "!ShowLoginDialog"", ActiveDocument.Name
is document name with ".vss" and not a project name. This should be
"ThisDocument.Vbproject.Name". But, this is rejected by the security option.
So the right project name should be written by hand like,
.OnAction = "CorrectProjectName!ShowLoginDialog"
 

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