我正在运行1904版的Excel(最新的Office 365每月发行版)。
我正在尝试向功能区中添加一个自定义的ComboBox,并带有一个可以在运行时更改的列表。
无论我做什么,都永远不会调用两次回调:getItemLabel
和getItemID
。因此,ComboBox永远不会充满任何数据。其他两个回调如预期的getItemCount
和onChange
一样被调用。
我本以为2个非行为回调将在getItemCount
之后被触发,但我只能在调试代码的去向时看到代码通过getItemCount
。 / p>
下面是我通过免费的 Microsoft Office自定义UI编辑器工具将其添加到Excel工作表中的XML文件的摘录:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="rxIRibbonUI_onLoad">
<ribbon>
<tabs>
<tab id="xlSherlockTab" label="Share Register" keytip="K" insertBeforeMso="TabHome">
<group id="customGroupSettings" label="Settings">
<comboBox id="cboSearchIssuer" label="Issuer" getItemCount="RibbonUI.SearchIssuer_getItemCount" getItemID="RibbonUI.SearchIssuer_getItemId" getItemLabel="RibbonUI.SearchIssuer_getItemLabel" onChange="RibbonUI.SearchIssuer_Click"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
包含在称为RibbonUI
的标准模块中的VBA代码相关部分的摘录:
'Callback for customUI.onLoad
Sub rxIRibbonUI_onLoad(ribbon As IRibbonUI)
MsgBox "ribbon_onLoad"
RibbonManager.SetRibbon ribbonParameter:=ribbon
ribbon.InvalidateControl ("cboSearchIssuer")
End Sub
''''''''''''''''''''
''rxcboSearchIssuer
''''''''''''''''''''
'Callback for rxcboSearchIssuer onChange
Sub SearchIssuer_Click(control As IRibbonControl, text As String)
MsgBox text
RibbonManager.GetRibbon().InvalidateControl ("cboSearchIssuer")
End Sub
'Callback for rxcboSearchIssuer getItemCount
Sub SearchIssuer_getItemCount(control As IRibbonControl, ByRef returnedVal)
MsgBox DASHBOARD.ListObjects(1).ListRows.Count
MsgBox control.id
returendVal = DASHBOARD.ListObjects(1).ListRows.Count
End Sub
''NOT BEING CALLED FROM HERE ONWARDS....
'Callback for rxcboSearchIssuer getItemLabel
Sub SearchIssuer_getItemLabel(control As IRibbonControl, index As Integer, ByRef returnedVal)
returnedVal = "Harry: " & CStr(index) 'DASHBOARD.ListObjects(1).ListRows(index).Range(1, 3)
End Sub
Sub SearchIssuer_getItemID(control As IRibbonControl, index As Integer, ByRef id)
id = "cbo" & CStr(index)
End Sub