VBA created menu in Visio 2002 is inactive?! 
Author Message
 VBA created menu in Visio 2002 is inactive?!

Using an example  from the Visio 200x documentation
(for the MenuItem-property)
a "Demo"|"Hello" - button is created on the menu .

The "Hello"-menu item works properly for Visio 2000, but
for the Visio 2002 this menu-item is inactive or greyed
out.

Is this a "bug" in Visio 2002??
Or any suggestions how to make this menu-item active?

(I'm using Visio 2002 Professional SR-1, and security is
set to "Low")

Morten

----from the Visio-documentation:

'This Microsoft Visual Basic for Applications (VBA) macro  
demonstrates adding a menu and menu item to the drawing
window 'menu set.It also sets the menu item's properties
such As: Caption, AddOnName, AddOnArgs, and ActionText.

Public Sub AddMenuItem_Example ()
    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

    Set UIObj = Visio.Application.BuiltInMenus

    Set menuSetsObj = UIObj.MenuSets

    'Get the drawing window menu set.
    Set menuSetObj=menuSetsObj.ItemAtId
(visUIObjSetDrawing)

    'Get the Menus collection.
    Set menusObj = menuSetObj.Menus

    'Add a Demo menu before the Window menu.
    Set menuObj = menusObj.AddAt(7)
    menuObj.Caption = "Demo"

    'Get the MenuItems collection.
    Set menuItemsObj = menuObj.MenuItems

    'Add a menu item to the new Demo menu.
    Set menuItemObj = menuItemsObj.Add

    'Set the properties for the new menu item.
    menuItemObj.Caption = "&Hello"
    menuItemObj.AddOnName = "MsgBox ""Hello"""
    'Tell Visio to use the new UI when the document is
active.
    ThisDocument.SetCustomMenus uiObj
End Sub



Tue, 03 May 2005 23:01:12 GMT  
 VBA created menu in Visio 2002 is inactive?!
Morten,

Many parts of Visio 2002 were modified to remove the ability to run random
VBA code; this was done to enhance security.  You'll need to change existing
code to place the inline VBA into a VBA method.  So the example becomes:

Public Sub AddMenuItem_Example ()
    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

    Set UIObj = Visio.Application.BuiltInMenus

    Set menuSetsObj = UIObj.MenuSets

    'Get the drawing window menu set.
    Set menuSetObj=menuSetsObj.ItemAtId(visUIObjSetDrawing)

    'Get the Menus collection.
    Set menusObj = menuSetObj.Menus

    'Add a Demo menu before the Window menu.
    Set menuObj = menusObj.AddAt(7)
    menuObj.Caption = "Demo"

    'Get the MenuItems collection.
    Set menuItemsObj = menuObj.MenuItems

    'Add a menu item to the new Demo menu.
    Set menuItemObj = menuItemsObj.Add

    'Set the properties for the new menu item.
    menuItemObj.Caption = "&Hello"
    menuItemObj.AddOnName = "ThisDocument.SayHello"
    'Tell Visio to use the new UI when the document is active.
    ThisDocument.SetCustomMenus uiObj
End Sub
Public Sub SayHello
    MsgBox "Hello"
End Sub

The Visio 2002 online help was modified to reflect this new requirement.

Michael J. Hunter
Microsoft Visio
michhu-at-online-dot-microsoft-dot-com

Developing Microsoft Visio Solutions:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devr...
Copyright_1270.asp?frame=true
Developer Resources for Microsoft Visio:
http://msdn.microsoft.com/library/default.asp?url=/nhp/Default.asp?co...
=28000456

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm



Sat, 07 May 2005 23:53:30 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. More Custom Menu Problems in Visio 2002

2. Custom Menu in Visio 2002

3. Visio 2002 custom menu frustration

4. Disabled custom menu items with VISIO 2002

5. Custom Menus in Visio 2002

6. Export a drawing to HTML with VBA and Visio 2002 (VisioXP)

7. Creating Visio 2002 Windows

8. Visio 2000 & Visio 2002 Differences

9. SendToBack in Visio 2000 & Visio 2002

10. visio diagram to XML / creating textfiles with VBA in Visio

11. Adding menu items to Project 2002 from VBA

12. Creating Custom Menu in OL 2002

 

 
Powered by phpBB® Forum Software