I have created a ribbon in Excel VBA and below is the snapshot of the code to create a combo box and add some items. The combo box gets created successfully, however the onChange event is not getting fired when I select any item.
ribbonXML = ribbonXML + " <mso:group id='StyleGruop' label='Styles'>" & vbNewLine
ribbonXML = ribbonXML + " <mso:button id='btnDeleteStyle' imageMso='PictureStylesGallery' screentip='Delete Styles' size='large' onAction='About_onAction'/>" & vbNewLine
ribbonXML = ribbonXML + " <mso:separator id='Separator4'/>" & vbNewLine
ribbonXML = ribbonXML + " <mso:dropDown id='ddlStyles' label='Style:' onAction='rxddSelectSheet_Click' getItemID='rxitemddSelectSheet_getItemId' getItemCount='rxitemddSelectSheet_getItemCount' getItemLabel='rxitemddSelectSheet_getItemLabel' />" & vbNewLine
'ribbonXML = ribbonXML + " <mso:dropDown id='ddlFreqStyles' label='Frequent Style:' getItemCount='Length1ItemCount' getItemLabel='Length1ListItem' onAction='Length1OnAction' getSelectedItemIndex='Length1ItemSelectedIndex' sizeString='centimeters' />" & vbNewLine
ribbonXML = ribbonXML + " <mso:comboBox id='MyMonth' label='Month:' showLabel='true' onChange='cbMonth_onChange' getItemID='cbMonth_getItemID' getItemCount='cbMonth_getItemCount' getItemLabel='cbMonth_getItemLabel' >" & vbNewLine
ribbonXML = ribbonXML + " <mso:item id='Month1' label='Jan'/>" & vbNewLine
ribbonXML = ribbonXML + " <mso:item id='Month2' label='Feb'/>" & vbNewLine
ribbonXML = ribbonXML + " <mso:item id='Month3' label='Mar'/>" & vbNewLine
ribbonXML = ribbonXML + " </mso:comboBox>" & vbNewLine
ribbonXML = ribbonXML + " </mso:group>" & vbNewLine
Below are the functions:
Public Sub cbMonth_getItemID(control As IRibbonControl, index As Integer, ByRef id)
'
' Code for getItemID callback. Ribbon control comboBox
'
returnedVal = "Month" & index
End Sub
Public Sub cbMonth_getItemCount(control As IRibbonControl, ByRef returnedVal)
'
' Code for getItemCount callback. Ribbon control comboBox
'
returnedVal = 12
End Sub
Public Sub cbMonth_getItemLabel(control As IRibbonControl, index As Integer, ByRef returnedVal)
'
' Code for getItemLabel callback. Ribbon control comboBox
'
returnedVal = Format(DateSerial(2011, 7 + index, 1), "mmm-yyyy") 'myMonth
End Sub
Public Sub cbMonth_onChange(control As IRibbonControl, Text As String)
'
' Code for onChange callback. Ribbon control comboBox
'
myMonth = Text
VBA.MsgBox myMonth
End Sub
Any help would be appreciated. Thanks in advance.
Hhhmmm, sorry but I'm not fully understanding what you've done. You can't create a Ribbon with VBA. There are different rules with VSTO... but that's a different issue. I assume you are trying VBA development.
So if this is the case, it looks to me that within the ribbon XML string, which is used to build the ribbon, and define the events isn't defining the OnChange event.
So basically, again assuming this is VBA, this is what I would do.... (there's lot of tutorials on Ribbon building on the web, so I'll not define the exact specifics here..)
If you've done steps 1 to 4 and the XML is correct, you're probably failing with steps 5. and/or 6.
Hope that helps....