共用方式為


Application.SetCustomToolbars method (Visio)

取代應用程式或文件目前的內建或自訂工具列。

語法

表情SetCustomToolbars (ToolbarsObject)

expression 代表 Application 物件的變數。

參數

名稱 必要/選用 資料類型 描述
工具列物件 必要 [IVUIOBJECT] 會傳回代表新自訂工具列之 UIObject 物件的運算式。

傳回值

註解

如果 ToolbarsObject 物件是在另一個程序中透過 VBA CreateObject 方法建立,而非取得應用程式或文件物件的適當屬性,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 支援與意見反應