Add menu item using Automation

R

Rad

I am trying to create a menu item, and the code is in a Stencil. I then load
the Stencil by running a script, which lunch Visio 2003, and creates
“Drawing1â€.
The code below works on a drawing page when it is in the document, but when
I put the code in the Stencil, the code does not work, because it is not
pointing to the ThisDocument (Drawing1). I need to make the code in the
Stencil point to the open and activated document so it can work.

Any solutions, or ideas?


Public Sub AddAt_Example()
Dim vsoUI As Visio.UIObject
Dim vsoMenuSets 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 UI object that represents Microsoft Office Visio built-in menus.
Set vsoUI = Visio.Application.BuiltInMenus

'Get the MenuSets collection.
Set vsoMenuSets = vsoUI.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 & MyMacro"
vsoMenuItem.AddOnName = "MyMacro"
vsoMenuItem.ActionText = "Run MyMacro"

'Tell Visio to use the new UI when the document is active.
ThisDocument.SetCustomMenus vsoUI

End Sub


Thanks,
Rad
 
R

Rad

I modified my code with :Application.ActiveDocument.SetCustomMenus vsoUI
which has created the menu item the way I need it.

The only problem now is:
I need to add a Reference to the Stencil programitacly?

Thanks,
Rad
 
R

Rad

I am not able to run
Modules("RS-Visio-Script-OLD").AddFromFile "C:\Program Files\Microsoft
Office\Visio11\1033\RS-Visio-Script-OLD.vss"

Not sure if I understand it????
 
J

JuneTheSecond

This is my example working in my PC.
Private strRefDwg As String
Private strRefStn As String

Sub SetReferences()
Dim myRef As Reference
Dim myRefs As References
Dim refDwg As Reference, refStn As Reference
Set myRefs = Application.Vbe.ActiveVBProject.References
Set refDwg = myRefs.AddFromFile("C:\Documents and
Settings\Administrator\My Documents\VisioDwg\Fname.vsd")
Set refStn = myRefs.AddFromFile("C:\Documents and
Settings\Administrator\My Documents\VisioDwg\Sname.vss")
strRefDwg = refDwg.Name
strRefStn = refStn.Name

For Each myRef In myRefs
Debug.Print myRef.Name, myRef.GUID, myRef.Major, myRef.Minor,
myRef.FullPath
Next

End Sub

Sub RemoveReferences()
Dim myRef As Reference
Dim myRefs As References
Set myRefs = Application.Vbe.ActiveVBProject.References

For Each myRef In myRefs
If myRef.Name = "Fname" Then myRefs.Remove myRef
If myRef.Name = "Sname" Then myRefs.Remove myRef
Next


For Each myRef In myRefs
Debug.Print myRef.Name, myRef.GUID, myRef.Major, myRef.Minor,
myRef.FullPath
Next

End Sub
 

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