我在Excel VBA中创建了一个功能区,下面是创建组合框并添加一些项目的代码快照。组合框已成功创建,但是当我选择任何项目时,onChange事件不会被触发。
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
以下是功能:
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
任何帮助将不胜感激。提前谢谢。
答案 0 :(得分:0)
因此,如果是这种情况,我认为在功能区XML字符串中,用于构建功能区,并定义事件并未定义OnChange事件。
所以基本上,再次假设这是VBA,这就是我要做的......(网上有很多关于Ribbon构建的教程,所以我不会在这里定义具体的细节......)
如果你已经完成了步骤1到4并且XML是正确的,那么你可能没有完成第5步和/或第6步。
希望有所帮助....