Table of contents
Collapse the table of content
Expand the table of content

CommandBarButton.State Property (Office)

office 365 dev account|Last Updated: 6/12/2017
1 Contributor

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 

See also


CommandBarButton Object

Other resources

CommandBarButton Object Members

© 2018 Microsoft