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

CommandBarComboBox.Change Event (Office)

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

Occurs when the end user changes the selection in a CommandBar combo box.

Note The use of CommandBars in some Microsoft Office applications has been superseded by the new ribbon component of the Microsoft Office Fluent user interface. For more information, search Help for the keyword "ribbon."


expression. Change( ByVal Ctrl As CommandBarComboBox )

expression A variable that represents a CommandBarComboBox object.


NameRequired/OptionalData TypeDescription
CtrlRequiredCommandBarComboBoxRepresents a CommandBar combo box.


The Change event is recognized by the CommandBarComboBox object. To return the Change event for a particular CommandBarComboBox control, use the WithEvents keyword to declare a variable, and then set the variable to the CommandBarComboBox control. When the Change event is triggered, it executes the macro or code that you specified with the OnAction property of the control.


The following example creates a command bar with a CommandBarComboBox control containing four selections. The combo box responds to user interaction through the CommandBarComboBox_Change event.

Private ctlComboBoxHandler As New ComboBoxHandler 
Sub AddComboBox() 

    Set HostApp = Application 

    Dim newBar As Office.CommandBar 
    Set newBar = HostApp.CommandBars.Add(Name:="Test CommandBar", Temporary:=True) 
    Dim newCombo As Office.CommandBarComboBox 
    Set newCombo = newBar.Controls.Add(msoControlComboBox) 
    With newCombo 
        .AddItem "First Class", 1 
        .AddItem "Business Class", 2 
        .AddItem "Coach Class", 3 
        .AddItem "Standby", 4 
        .DropDownLines = 5 
        .DropDownWidth = 75 
        .ListHeaderCount = 0 
    End With 
    ctlComboBoxHandler.SyncBox newCombo 
    newBar.Visible = True  

End Sub

The preceding example relies on the following code, which is stored in a class module in the VBA project.

Private WithEvents ComboBoxEvent As Office.CommandBarComboBox 
Public Sub SyncBox(box As Office.CommandBarComboBox) 
    Set ComboBoxEvent = box 
    If Not box Is Nothing Then 
        MsgBox "Synced " & box.Caption & " ComboBox events." 
    End If 

End Sub 

Private Sub Class_Terminate() 
    Set ComboBoxEvent = Nothing 
End Sub 

Private Sub ComboBoxEvent_Change(ByVal Ctrl As Office.CommandBarComboBox) 
    Dim stComboText As String 

    stComboText = Ctrl.Text 

        Select Case stComboText 
        Case "First Class" 
        Case "Business Class" 
        Case "Coach Class" 
        Case "Standby" 
    End Select 

End Sub 
Private Sub FirstClass() 
    MsgBox "You selected First Class reservations" 
End Sub 
Private Sub BusinessClass() 
    MsgBox "You selected Business Class reservations" 
End Sub 
Private Sub CoachClass() 
    MsgBox "You selected Coach Class reservations" 
End Sub 
Private Sub Standby() 
    MsgBox "You chose to fly standby" 
End Sub

See also


CommandBarComboBox Object

Other resources

CommandBarComboBox Object Members

© 2018 Microsoft