preston
preston

Reputation: 145

Excel Ribbon customisation: Dynamic menu, getContent and OnAction

The code below produces the following error, caused by the OnAction part: "Wrong number of arguments or invalid property assignment".

Sub GetContent(control As IRibbonControl, ByRef returnedVal)
Dim xml As String
Dim i As Integer
lastRow = ActiveSheet.Range("A100").End(xlUp).Row

xml = "<menu xmlns=""http://schemas.microsoft.com/office/2009/07/customui"">"

For i = 2 To lastRow
    xml = xml & "<button id=" & """but" & i & """" & " label=""" & ActiveSheet.Range("A" & i).Value & """" & " onAction=" & """" &     ActiveSheet.Range("B" & i).Value & """" & " />"
Next

xml = xml & "</menu>"

returnedVal = xml
End Sub

The goal is to create a dynamic menu in the ribbon based on input in two columns in a worksheet, one with table name (A) and one with macro name (B).

Upvotes: 1

Views: 1721

Answers (1)

preston
preston

Reputation: 145

I just found the solution. I needed the following in the macros I was trying to execute with the onAction statements:

ByRef control As IRibbonControl

so:

Sub Table1(ByRef control As IRibbonControl)
code
end sub

Upvotes: 2

Related Questions