I have been using this post as a guide to pass variables until now Excel, VBA: How to pass multiple variables to .OnAction
And it has worked very well. Unfortunately, I am trying to pass a worksheet argument this time, and it is not working. Here is a block of code so you can take a look. It is for a right click menu:
With menu.Controls.Add(Temporary:=True, Type:=msoControlButton, before:=i_menu)
.BeginGroup = False
' ' ' ' ' ' .OnAction = "'" & ThisWorkbook.Name & "'!" & "'saute """ & num_doc & """,""" & num_etape & """'"
.OnAction = "'" & ThisWorkbook.Name & "'!" & "'saute """ & num_doc & """,""" & num_etape & """,""" & ws & """'"
.FaceId = 478
.Caption = "Sauté"
.Tag = "commande_custom"
End With
The line with multiple apostrophes is my old line, that was working. I added a worksheet argument just under it. For reference, saute
is a sub, and its arguments are (num_doc as string, num_etape as string, ws as Worksheet). I have also tried using two fewer quotation marks both left and right of ws, to no avail. Can anyone help figure out how to send, and/or propose another way of sending the information to my Sub (be it a string or something else)?
Apparently, after fiddling with it, I figured out that a Worksheet takes not one, not three, but TWO quotations around it. With numeric variables and variants taking 1 pair of quotations, and strings taking 3. Resolved line: