Search code examples
xmlvbaexcelribbon

How to get the value of a dropDown control?


dropDown on the ribbon:

<dropDown id="dd01"
onAction="dd01OnAction"/>

In VBA I need

Sub dd01OnAction(control As IRibbonControl, ID As String, index As Integer)
If dd01.Value = "Sky" Then MsgBox "323"
End Sub

How can I get the value of dropDown ?


Solution

  • I don't think you can get the value directly.

    I usually load the dropDowns from a collection object and make sure that the ID in the collection matches the index in the dropDown. That way I can get all relevant values from the collection based on the index or ID parameter in the callback. Could you use something similar as a workaraound?

    does that mean that after each change in Collection, I need to Invalidate ribbon ? Mamma Mia, it will be almost after each click

    Yes, however, by using ribbonobject.InvalidateControl("ID") you can invalidate just the specific dropDown control, not the whole ribbon.

    Very brief example:

    Sub dd01OnAction(control As IRibbonControl, ID As String, index As Integer)
        '***** Assumes that MyCollection is initialized elsewhere
        '***** and filled with strings :)
        Debug.Print "The value is " & MyCollection.Item(index)
    
        If MyCollection.Item(index) = "Sky" Then MsgBox "323"
    
    End Sub