Dynamically populate dynamicMenu in excel UI Ribbon

3.5k views Asked by At

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?

1

There are 1 answers

0
Hugo On BEST ANSWER

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