ToolbarItem.State property (Visio)
Determines a button's state, pressed or not pressed. Read/write.
Syntax
expression.State
expression A variable that represents a ToolbarItem object.
Return value
Integer
Remarks
Note
Starting with Visio 2010, the Microsoft Office Fluent user interface (UI) replaced 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.
The State property can be one of the following constants declared by the Visio type library in VisUIButtonState.
Constant | Value | Description |
---|---|---|
visButtonUp | 0 | Button is not pressed |
visButtonDown | -1 | Button is pressed |
Example
This example shows how to use the State property to set the state of a toolbar button (make it appear pressed). The example adds a custom toolbar button to the Standard toolbar. Pressing the button saves the active document. This button appears in the Microsoft Visio user interface and is available while the document is active.
Before running this code, replace path\filename
with the full path to and name of a valid icon (.ico) file on your computer.
To restore the built-in Visio toolbars after you run this macro, call the ThisDocument.ClearCustomToolbars method.
Sub State_Example()
Dim vsoUIObject As Visio.UIObject
Dim vsoToolbarSet As Visio.ToolbarSet
Dim vsoToolbarItems As Visio.ToolbarItems
Dim vsoToolbarItem As Visio.ToolbarItem
'Check whether there are document custom toolbars.
If ThisDocument.CustomToolbars Is Nothing Then
'If not, check whether there are application custom toolbars.
If Visio.Application.CustomToolbars Is Nothing Then
'If there are no custom toolbars, use the built-in toolbars.
Set vsoUIObject = Visio.Application.BuiltInToolbars(0)
Else
'If there are application custom toolbars, copy them.
Set vsoUIObject = Visio.Application.CustomToolbars.Clone
End If
Else
'If there already are document custom toolbars, use them.
Set vsoUIObject = ThisDocument.CustomToolbars
End If
'Get the Toolbars collection for the drawing window context.
Set vsoToolbarSet = vsoUIObject.ToolbarSets.ItemAtID(visUIObjSetDrawing)
'Get the set of toolbar items for the Standard toolbar.
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 = visCmdFileSave
vsoToolbarItem.Style = visButtonIconandCaption
vsoToolbarItem.State = visButtonDown
vsoToolbarItem.IconFileName "path\filename"
'Use the new UIObject object while this document is active.
ThisDocument.SetCustomToolbars vsoUIObject
End Sub
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for