Visio2000: Sample Macro to Add a Custom Menu Item (278534)



The information in this article applies to:

  • Microsoft Visio 2000 Standard Edition
  • Microsoft Visio 2000 Professional Edition
  • Microsoft Visio 2000 Technical Edition
  • Microsoft Visio 2000 Enterprise Edition

This article was previously published under Q278534

SUMMARY

This article contains a sample Microsoft Visual Basic for Applications macro (Sub procedure) to add a new menu item.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The following sample Visual Basic for Applications macro demonstrates how to use the UI object and MenuSets collection to add a new menu item called Example to the File menu in Visio.
Option Explicit

Public Sub HelloWorld()

   MsgBox "Hello World", vbInformation + vbOKOnly, "Microsoft Visio"

End Sub

 
Public Sub AddMenuItem()
 
   Dim uiObj As Visio.UIObject
   Dim visMenuSets As Visio.MenuSets
   Dim visMenuSet As Visio.MenuSet
   Dim visMenus As Visio.Menus
   Dim visMenu As Visio.Menu
   Dim visMenuItems As Visio.MenuItems
   Dim visMenuItem As Visio.MenuItem
        
   Set uiObj = Visio.Application.BuiltInMenus
   Set visMenuSets = uiObj.MenuSets

   ' Get the Visio object context menu set.
   Set visMenuSet = visMenuSets.ItemAtID(visUIObjSetDrawing)
   Set visMenus = visMenuSet.Menus

   ' Get the file menu from the menus collection.
   Set visMenu = visMenus.Item(0)

   ' Get the items collection from the file menu
   Set visMenuItems = visMenu.MenuItems
    
   ' Add Example Menu Item to the File menu in the 4th position
   Set visMenuItem = visMenuItems.AddAt(3)
   visMenuItem.Caption = "Example"
    
   ' Have Example run the HelloWorld Sub procedure
   visMenuItem.AddOnName = "ThisDocument.HelloWorld"
    
   ' Set the new menus.
   Visio.Application.SetCustomMenus uiObj

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

End Sub
				
For additional information about using the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:

277011 Visio2000: How to Run Sample Code from Knowledge Base Articles


Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbdtacode KB278534