Excel Ribbon 组合框:如何设置 onChange 回调

问题描述 投票:0回答:1

在自定义功能区中设置组合框。

不明白,如何构建onChange回调。

这是组合框 XML:

<group id="GroupDemo2" 
    label="SelectSheet"
    autoScale="true"
    imageMso="AddInManager">
    <comboBox id="ComboBox001"
        label="comboBox001”
        sizeString=“XXXX”
        onChange="RibbonCallbacks.ComboBox001OnChange"
        getText="RibbonCallbacks.ComboBox001GetText">
        <item id="ItemOne”
            label=“One”/>
        <item id="ItemTwo”
            label=“Two”/>
        <item id="ItemThree”
            label=“Three”/>
    </comboBox>
</group>     

我尝试过这个,但没有做任何事情:

Sub ComboBox001OnChange(control As IRibbonControl, id As String)
    Select Case id
        Case "ItemOne”
            Sheets("Sheet1”).Select
        Case "ItemTwo”
            Sheets("Sheet2”).Select
        Case "ItemThree”
            Sheets("Sheet3”).Select
    End Select
End Sub

它适用于下拉菜单,但不适用于组合框。

然后是第二个回调:

'Callback for ComboBox001 getText
Sub ComboBox001GetText(control As IRibbonControl, ByRef returnedVal)
    returnedVal = "One"
End Sub

我也需要这个吗?

谢谢!

excel vba combobox ribbonx
1个回答
0
投票

您的报价有问题,他们没有验证,修复报价后现在已验证,看起来可以正常工作。

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <ribbon>
        <tabs>
            <tab id="customTab" label="Contoso" insertAfterMso="TabHome">
    <group id="GroupDemo2" 
    label="SelectSheet"
    autoScale="true"
    imageMso="AddInManager">
    <comboBox id="ComboBox001"
        label="comboBox001"
        sizeString="XXXX"
        onChange="RibbonCallbacks.ComboBox001OnChange"
        getText="RibbonCallbacks.ComboBox001GetText">
        <item id="ItemOne"
            label="One"/>
        <item id="ItemTwo"
            label="Two"/>
        <item id="ItemThree"
            label="Three"/>
    </comboBox>
</group>     
            </tab>
        </tabs>
    </ribbon>
</customUI>

关于第二个子。检查 Microsoft doc 中的组合框,在功能区中搜索 getText 并决定是否需要它。 https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.ribbon.ribboncombobox?view=windowsdesktop-8.0#events

© www.soinside.com 2019 - 2024. All rights reserved.