CommandBarButton.State Property (Office)

Office 2013 and later

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

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

expression .State

expression Required. A variable that represents a CommandBarButton object.

The State property of built-in command bar buttons is read-only. The value of the Type property is available as a value in the MsoButtonState enumeration.

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.

 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) 
 With myControl1 
 .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) 
 With myControl2 
 .State = msoButtonDown 
 End With