Toolbar.Protection 属性 (Visio)

确定如何保护 Toolbar 对象以避免用户自定义。 读/写。

语法

表达式保护

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

返回值

整数

备注

注意

从 Visio 2010 开始,Microsoft Office Fluent 用户界面 (UI) 替换了以前的分层菜单、工具栏和任务窗格系统。 用于在以前版本的 Visio 中自定义用户界面的 VBA 对象和成员在 Visio 中仍可用,但它们的功能不同。

Protection 属性值可以是由 Visio 类型库在 VisUIBarProtection 中声明的下列常量之一或它们的组合。

常量 Description
visBarNoProtection 0 无保护。
visBarNoCustomize 1 不能自定义。
visBarNoResize 2 不能调整大小。
visBarNoMove 4 不能移动。
visBarNoChangeDock 16 不能固定或浮动。
visBarNoVerticalDock 32 不能垂直固定。
visBarNoHorizontalDock 64 不能水平固定。

示例

以下示例说明如何使用 Protection 属性防止用户固定自定义工具栏。 该示例将一个自定义工具栏添加到 Toolbars 集合,然后向该工具栏添加一个按钮。 该工具栏出现在 Microsoft Visio 用户界面中,并且在文档处于活动状态时可用。

运行此宏后,要恢复 Visio 的内置工具栏,请调用 ThisDocument.ClearCustomToolbars 方法。

 
Sub Protection_Example() 
 
 Dim vsoUIObject As Visio.UIObject 
 Dim vsoToolbars As Visio.Toolbars 
 Dim vsoToolbar As Visio.Toolbar 
 Dim vsoToolbarItem As Visio.ToolbarItem 
 
 'Check whether there are document custom toolbars. 
 If ThisDocument.CustomToolbars Is Nothing Then 
 
 'Check whether there are application custom toolbars. 
 If Visio.Application.CustomToolbars Is Nothing Then 
 
 'Use the built-in toolbars. 
 Set vsoUIObject = Visio.Application.BuiltInToolbars(0) 
 
 Else 
 
 'Use the application custom toolbars. 
 Set vsoUIObject = Visio.Application.CustomToolbars.Clone 
 
 End If 
 
 Else 
 
 'Use the document custom toolbars. 
 Set vsoUIObject = ThisDocument.CustomToolbars 
 
 End If 
 
 'Get the Toolbars collection for the drawing window context. 
 Set vsoToolbars = vsoUIObject.ToolbarSets.ItemAtID( _ 
 Visio.visUIObjSetDrawing).Toolbars 
 
 'Add a toolbar to the collection. 
 Set vsoToolbar = vsoToolbars.Add 
 With vsoToolbar 
 
 'Set the title of the toolbar. 
 .Caption = "My New Toolbar" 
 
 'Float the toolbar at coordinates (300,200). 
 .Position = Visio.visBarFloating 
 .Left = 300 
 .Top = 200 
 
 'Disallow docking the new toolbar. 
 .Protection = Visio.visBarNoHorizontalDock _ 
 + Visio.visBarNoVerticalDock 
 
 End With 
 
 'Add an item to the toolbar. 
 Set vsoToolbarItem = vsoToolbar.ToolbarItems.Add 
 With vsoToolbarItem 
 
 'Set the new item to be a button. 
 .CntrlType = Visio.visCtrlTypeBUTTON 
 
 'Set the icon of the new button. 
 .FaceID = Visio.visIconIXCUSTOM_CARDS 
 
 'Set the CmdNum property of the new button 
 .CmdNum = 1 
 
 'Set the Width property of the new button 
 'wide enough that the toolbar name is readable. 
 .Width = 100 
 
 End With 
 
 'Tell Visio to use the new UIObject object while 
 'this document is active. 
 ThisDocument.SetCustomToolbars vsoUIObject 
 
End Sub

支持和反馈

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