Share via


SetCustomToolbars Method [Visio 2003 SDK Documentation]

Replaces the current built-in or custom toolbars of an application or document.

object**.SetCustomToolbars** (ToolbarsObject)

object     Required. An expression that returns an Application or Document object to receive the custom toolbars.

ToolbarsObject    Required. An expression that returns a UIObject object that represents the new custom toolbars.

Version added

4.0

Remarks

If the ToolbarsObject object was created in a separate process by using the VBA CreateObject method instead of getting the appropriate property of an Application or Document object, the SetCustomToolbars method returns an error.

Example

This Microsoft Visual Basic for Applications (VBA) macro shows how to use the SetCustomToolbars method to replace the built-in toolbar set with the custom set. It retrieves a copy of the built-in Visio toolbars, adds a toolbar button, sets the button icon, and then replaces the toolbar set.

Before running this macro, replace path\filename in the code with the full path to and filename of an icon file (.ico) on your computer.

Public Sub Set CustomToolbars_Example() 
 
    Dim vsoUIObject As Visio.UIObject 
    Dim vsoToolbarSet As Visio.ToolbarSet   
    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) 

    'Get the ToolbarItems collection. 
    Set vsoToolbarItems = vsoToolbarSet.Toolbars(0).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 = 1 

    'Set the toolbar button icon. 
    vsoToolbarItem.IconFileName "path\filename" 

    'Use the new custom UI. 
    ThisDocument.SetCustomToolbars vsoUIObject 

End Sub  

Applies to | Application object | Document object | InvisibleApp object

See Also | CustomToolbars property | SetCustomMenus method | UIObject object