How to set default value in dropdown control for Excel custom ribbon control

前端 未结 3 953
一向
一向 2021-02-09 00:54

I have created a custom Fluent Ribbon interface for Excel 2010 which includes a dropdown. Relevant XML code (simplified):



        
3条回答
  •  不思量自难忘°
    2021-02-09 01:47

    I cheated shamelessly to get this XML - I used RibbonCreator 2010.

    The DefaultValue appears to be set in the dropDown's tag of all the ridiculous places...

    
        
        
    
    

    EDIT:

    This won't work unless you add the following functions to your VBA code:

    Sub GetSelectedItemIndexDropDown(control As IRibbonControl, ByRef index)
        ' Callbackname in XML File "GetSelectedItemIndexDropDown"
        ' Callback getSelectedItemIndex
        Dim varIndex As Variant
        varIndex = getTheValue(control.Tag, "DefaultValue")
        If IsNumeric(varIndex) Then
            Select Case control.ID
                ''GetSelectedItemIndexDropDown''
                Case Else
                    index = getTheValue(control.Tag, "DefaultValue")
            End Select
        End If
    End Sub
    
    Public Function getTheValue(strTag As String, strValue As String) As String
       Dim workTb()     As String
       Dim Ele()        As String
       Dim myVariabs()  As String
       Dim i            As Integer
       On Error Resume Next
          workTb = Split(strTag, ";")
          ReDim myVariabs(LBound(workTb) To UBound(workTb), 0 To 1)
          For i = LBound(workTb) To UBound(workTb)
             Ele = Split(workTb(i), ":=")
             myVariabs(i, 0) = Ele(0)
             If UBound(Ele) = 1 Then
                myVariabs(i, 1) = Ele(1)
             End If
          Next
          For i = LBound(myVariabs) To UBound(myVariabs)
             If strValue = myVariabs(i, 0) Then
                getTheValue = myVariabs(i, 1)
             End If
          Next
    End Function
    

    However, it could be made sufficiently generic that once it was in place, it could be referred to repeatedly in XML.

提交回复
热议问题