Document.SetCustomToolbars 方法 (Visio)

替换应用程序或文档的当前内置或自定义工具栏。

语法

表达式SetCustomToolbars (ToolbarsObject)

表达 一个代表 Document 对象的变量。

参数

名称 必需/可选 数据类型 说明
ToolbarsObject 必需 [IVUIOBJECT] 一个返回 UIObject 对象的表达式,该对象代表新的自定义工具栏。

返回值

Nothing

注解

如果 ToolbarsObject 对象是在单独的进程中创建的,方法是使用 VBA CreateObject 方法而不是获取 ApplicationDocument 对象的相应属性, SetCustomToolbars 方法将返回错误。

示例

以下 Microsoft Visual Basic for Applications (VBA) 宏说明如何使用 SetCustomToolbars 方法用自定义工具栏集替换内置工具栏集。 它先检索内置 Visio 工具栏的副本,添加一个工具栏和工具栏按钮,设置该按钮的图标,然后替换工具栏集。

在运行此宏之前,请将代码中的 path\filename 替换为计算机上 (.ico) 图标文件的完整路径和文件名。

Public Sub SetCustomToolbarItems_Example() 
 
 Dim vsoUIObject As Visio.UIObject 
 Dim vsoToolbarSet As Visio.ToolbarSet 
 Dim vsoToolbar As Visio.Toolbar 
 Dim vsoToolbarItems As Visio.ToolbarItems 
 Dim vsoToolbarItem As Visio.ToolbarItem 
 
 'Get the UIObject object for the copy of the built-in toolbars. 
 Set vsoUIObject = Visio.Application.BuiltInToolbars(0) 
 
 'Get the drawing window toolbar sets. 
 'NOTE: Use ItemAtID to get the toolbar set. 
 'Using vsoUIObject.ToolbarSets(visUIObjSetDrawing) will not work. 
 Set vsoToolbarSet = vsoUIObject.ToolbarSets.ItemAtID(visUIObjSetDrawing) 
 
 'Create a new toolbar 
 Set vsoToolbar = vsoToolbarSet.Toolbars.Add 
 
 With vsoToolbar 
 .Caption = "test" 
 .Position = visBarFloating 
 .Left = 300 
 .Top = 200 
 
 .Protection = visBarNoHorizontalDock 
 .Visible = True 
 .Enabled = True 
 End With 
 
 'Get the ToolbarItems collection. 
 Set vsoToolbarItems = vsoToolbar.ToolbarItems 
 
 'Add a new button in the first position. 
 Set vsoToolbarItem = vsoToolbarItems.AddAt(0) 
 
 'Set properties for the new toolbar button. 
 vsoToolbarItem.CntrlType = visCtrlTypeBUTTON 
 vsoToolbarItem.CmdNum = visCmdPanZoom 
 
 'Set the toolbar button icon. 
 vsoToolbarItem.IconFileName "path\filename " 
 
 'Use the new custom UI. 
 ThisDocument.SetCustomToolbars vsoUIObject 
 
End Sub

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。