xmlexceluiribbonvba

Dynamically populate dynamicMenu in excel UI Ribbon


I want to populate a dynamicMenu in a custom Excel Ribbon from a list in a sheet. My xml code is this:

<dynamicMenu id="A" label="Menu A" imageMso="FormatPainter" getContent="GetMenuContent" />

I can see the menu. What I don´t have is the GetMenuContent callback, but I understand that there is where the macro to populate the menu should go right?


Solution

  • Solved! Got the answer from this link.

    just direct your getContent instruction to this macro:

    Sub GetContent(control As IRibbonControl, ByRef returnedVal)
        Dim xml As String
    
        xml = "<menu xmlns=""http://schemas.microsoft.com/office/2009/07/customui"">" & _
              "<button id=""but1"" imageMso=""Help"" label=""Help"" onAction=""HelpMacro""/>" & _
              "<button id=""but2"" imageMso=""FindDialog"" label=""Find"" onAction=""FindMacro""/>" & _
              "</menu>"
    
        returnedVal = xml
    End Sub
    
    Sub HelpMacro(control As IRibbonControl)
        MsgBox "Help macro"
    End Sub
    
    Sub FindMacro(control As IRibbonControl)
        MsgBox "Find macro"
    End Sub