Microsoft KB Archive/278534

= Visio2000: Sample Macro to Add a Custom Menu Item =

Article ID: 278534

Article Last Modified on 1/29/2007

-

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 &quot;Hello World&quot;, vbInformation + vbOKOnly, &quot;Microsoft Visio&quot;

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 = &quot;Example&quot; ' Have Example run the HelloWorld Sub procedure visMenuItem.AddOnName = &quot;ThisDocument.HelloWorld&quot; ' 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

Additional query words: vb vba vbe

Keywords: kbdtacode KB278534

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.