Home » excel » Excel, VBA: How to pass multiple variables to .OnAction

Excel, VBA: How to pass multiple variables to .OnAction

Posted by: admin March 9, 2020 Leave a comment

Questions:

I am trying to pass multiple variables to a .OnAction call for a button. I have not been able to find answers that relate to multiple variables, and I can do it with just one variable. Here is what I have that works for one variable:

shpBar.OnAction = "'Button_Click """ & strText & """'"

How can I add two other variables to this (such as VarA and VarB)?

How to&Answers:

Assuming that VarA and VarB are variants or numeric variables, this would work:

.OnAction = "'Button_Click """ & strText & """," & varA & "," & varB & " '"

If they are strings, you need to add two more double-quotes around each variable name.

.OnAction = "'Button_Click """ & strText & """,""" & varA & """,""" & varB & """ '"