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)?
VBA allows you to pass variables into subroutines and functions in two ways. You can specify either ByVal or ByRef for each of the variables that are passed in. The ByVal and ByRef distinction for subroutine and function parameters is very important to make. In VBA all objects are passed by reference.
Setting variables In many programming languages, you can assign a value to the variable in the same statement that you use to declare it. In VBA, declaring variables is optional, but you can't declare AND set the variable at the same time. We've added a line that assigns the value of a variable.
We must type in the name of the macro and then also the value for the argument. Type in the name of the macro and then a space and then the value that you want to send to the macro. Note: the text is surrounded by double quotation marks and then the entire thing is surrounded by single quotation marks.
Pass Text Values: Let's send a text value to the macro. When you send a text value, you must always put double quotation marks around it. Note: when you pass a value using the Call method, the second example, you must put the values within parentheses.
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 & """ '"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With