Excel,VBA:如何将多个变量传递给.OnAction

时间:2022-03-19 05:49:24

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:

我试图将多个变量传递给.OnAction调用按钮。我无法找到与多个变量相关的答案,我只能用一个变量来完成。以下是我对一个变量有效的方法:

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

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

如何为此添加另外两个变量(例如VarA和VarB)?

1 个解决方案

#1


10  

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

假设VarA和VarB是变体或数字变量,这将起作用:

.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 & """ '"

#1


10  

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

假设VarA和VarB是变体或数字变量,这将起作用:

.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 & """ '"