1

The code below create dynamic menu with checkboxes. Each time the user must select the menu to select an item. I would like to avoid that and click only one time on the nenu.

Here the xml

<dynamicMenu id="MnuSelectOtherDB"
             label="Select Other Databases"
             getContent="GetContentCallback"/>

Here the VBA code

Sub GetContentCallback(control As IRibbonControl, _
                       ByRef XMLString)
    ' Callback get the selected datbases

    Dim lngDummy    As Long
    Dim strDummy    As String
    Dim strContent  As String
    strDummy = "<menu xmlns=""http://schemas.microsoft"
    strDummy = strDummy & ".com/office/2006/01/customui"">"

        For lngDummy = 0 To 5
            strContent = strContent & _
            "<checkBox id=""MyDynaCheckbox" & lngDummy & _
            """ label =""Dynamic Item" & _
            lngDummy & """/>"
        Next

    strDummy = strDummy & strContent & " </menu>"
    XMLString = strDummy
End Sub

Here screen shots

enter image description here

Here video of the issue Dynamic menu on ribbon

Jean-Marc Flamand
  • 939
  • 3
  • 10
  • 24

3 Answers3

0

according to Cindy, ribbon control do not allow it. it's impossible for now!

Jean-Marc Flamand
  • 939
  • 3
  • 10
  • 24
0

you can try Sendkey to re-expand the menu

    ' for my case ALT + Y2 then Y4 is shortcut key to activate element of CustomUI element
    Application.SendKeys ("%Y2Y4")
Amit Panasara
  • 600
  • 8
  • 16
0

"try this

Public GLOBAL_VARIBLE as LONG 
Public GobjRibbon as iribbonUI


Sub GetContentCallback(control As IRibbonControl, _
                       ByRef XMLString)
    ' Callback get the selected datbases

    Dim lngDummy    As Long
    Dim strDummy    As String
    Dim strContent  As String
    strDummy = "<menu xmlns=""http://schemas.microsoft"
    strDummy = strDummy & ".com/office/2006/01/customui"">"

        For lngDummy = 0 To 5
            strContent = strContent & _
            "<checkBox id=""MyDynaCheckbox" & lngDummy & _
            """ label =""Dynamic Item" & _
            lngDummy & "" onAction=""FUNCTION_TO_SET_GLOBAL"" getPressed=""YOUR_FUNCTION_NAME"""/>"
        Next

    strDummy = strDummy & strContent & " </menu>"
    XMLString = strDummy
End Sub



Public Function FUNCTION_TO_SET_GLOBAL(ctl as IRibbonControl)
GLOBAL_VARIBLE  = clng(mid(ctl.id,13))
GobjRibbon.invalidate
end function



Public Function YOUR_FUNCTION_NAME(ctl as IRibbonControl, ByRef Checked)
 Checked = (ctl.id = "Dynamic Item" & GLOBAL_VARIBLE)
end function