Share via


CommandBarButton.State Property

Office Developer Reference
Aa432921.vs_note(en-us,office.12).gif  Note
The Microsoft Office Assistant has been deprecated in the 2007 release of the Microsoft Office system.

Gets or sets the appearance of a CommandBarButton control. Read/write.

Syntax

expression.State

expression   Required. A variable that represents a CommandBarButton object.

Remarks

It should be noted that the State property of built-in command bar buttons is read-only.

Example

This example creates a command bar named "Custom" and adds two buttons to it. The example then sets the button on the left to msoButtonUp and sets the button on the right to msoButtonDown.

Visual Basic for Applications
      Dim myBar As Office.CommandBar
    Dim imgSource As Office.CommandBarButton
    Dim myControl1 As Office.CommandBarButton
    Dim myControl2 As Office.CommandBarButton
    ' Add new command bar.
    Set myBar = CommandBars.Add(Name:="Custom", Position:=msoBarTop, Temporary:=True)
    ' Add 2 buttons to new command bar.
    With myBar
        .Controls.Add Type:=msoControlButton
        .Controls.Add Type:=msoControlButton
        .Visible = True 
    End With
    ' Paste Bold button face and set State of first button.
    Set myControl1 = myBar.Controls(1)
    Set imgSource = CommandBars.FindControl(msoControlButton, 113)
    imgSource.CopyFace
    With myControl1
        .PasteFace
        .State = msoButtonUp
    End With
    ' Paste italic button face and set State of second button.
    Set myControl2 = myBar.Controls(2)
    Set imgSource = CommandBars.FindControl(msoControlButton, 114)
    imgSource.CopyFace
    With myControl2
        .PasteFace
        .State = msoButtonDown
    End With

See Also