Move the below line out of the sub and place it above the sub:
Dim MyList As CommandBarComboBox
See below:
Option Explicit
Dim MyList As CommandBarComboBox
Sub test()
'Let's create the menubarDim sht As Worksheet
Dim MyBar As CommandBar
Dim MyButton, MyButton2 As CommandBarButton
On Error Resume Next
Application.CommandBars("Sheet Navigate").Delete 'If the command bar was created before, it is deleted.
On Error GoTo 0
Set MyBar = CommandBars.Add("Sheet Navigate", , False, True)
With MyBar
With .Controls.Add(Type:=msoControlButton)
.Caption = "Button that is not a button"
.Style = msoButtonCaption
End With
Set MyList = .Controls.Add(msoControlDropdown) 'Drop-down list is being created.
With MyList
.AddItem "One"
.AddItem "Two"
.AddItem "Three"
.OnAction = "Sheet_Navigate" 'Macro name that triggered by drop-down list
.ListIndex = 1
End With
.Protection = msoBarNoCustomize
.Position = msoBarTop
.Visible = True
End With
End Sub
Sub Sheet_Navigate()
Debug.Print MyList.List(MyList.ListIndex) ' value from selected option
Debug.Print MyList.ListIndex ' selected list index
End Sub