Table of contents

InvisibleApp.SetCustomMenus 方法 (Visio)InvisibleApp.SetCustomMenus Method (Visio)

office 365 dev account|上次更新日期: 2018/3/13
2 参与人员

替换应用程序或文档的当前内置或自定义菜单。Replaces the current built-in or custom menus of an application or document.


表达式SetCustomMenus( MenusObject )expression . SetCustomMenus( MenusObject )

表达式_一个表示InvisibleApp对象的变量。_expression A variable that represents an InvisibleApp object.


名称Name必需/可选Required/Optional数据类型Data Type说明Description
MenusObjectMenusObject必需Required[IVUIOBJECT][IVUIOBJECT]该表达式返回一个UIObject对象,该对象表示的新的自定义菜单。An expression that returns a UIObject object that represents the new custom menus.

返回值Return Value



请注意 从 Visio,Microsoft Office 流畅的用户界面 (UI) 替换的前一个系统的分层的菜单、 工具栏和任务窗格。VBA 对象和用于自定义用户界面,在 Visio 的以前版本中的成员仍可在 Visio 中,但它们的功能有所不同。Note Starting with Visio, the Microsoft Office Fluent user interface (UI) replaces the previous system of layered menus, toolbars, and task panes. VBA objects and members that you used to customize the user interface in previous versions of Visio are still available in Visio, but they function differently.

如果UIObject对象而不是获取应用程序文档对象的相应属性使用无论过程创建一个单独的进程中, SetCustomMenus方法将返回一个错误。If the UIObject object was created in a separate process by using the CreateObject procedure instead of getting the appropriate property of an Application or Document object, the SetCustomMenus method returns an error.


以下 Microsoft Visual Basic for Applications (VBA) 宏说明如何将菜单和菜单项添加到用户界面中,然后用自定义菜单集替换内置菜单集。This Microsoft Visual Basic for Applications (VBA) macro shows how to add a menu and menu item to the user interface, and then replace the built-in menu set with the custom set.

若要运行该宏后,请恢复 Microsoft Visio 内置的用户界面,则调用ThisDocument.ClearCustomMenus方法。To restore the Microsoft Visio built-in user interface after you run this macro, call the ThisDocument.ClearCustomMenus method.

Public Sub SetCustomMenus_Example() 

 Dim vsoUIObject 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 the Microsoft Visio built-in menus. 
 Set vsoUIObject = Visio.Application.BuiltInMenus 

 'Get the MenuSets collection. 
 Set vsoMenuSets = vsoUIObject.MenuSets 

 'Get the drawing window menu set. 
 Set vsoMenuSet = vsoMenuSets.ItemAtID(visUIObjSetDrawing) 

 'Get the Menus collection. 
 Set vsoMenus = vsoMenuSet.Menus 

 'Add a Demo menu. 
 Set vsoMenu = vsoMenus.AddAt(1) 
 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 = "&;Hello" 
 vsoMenuItem.AddOnName = "MsgBox ""Hello""" 

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

End Sub
© 2018 Microsoft