Custom menu Passing a WorkSheet variable through .

2019-09-17 07:32发布

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)?

1条回答
对你真心纯属浪费
2楼-- · 2019-09-17 08:17

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:

.OnAction = "'" & ThisWorkbook.Name & "'!" & "'saute """ & num_doc & """,""" & num_etape & ""","" & ws & ""'"
查看更多
登录 后发表回答