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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13079727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 18:15:41  来源:igfitidea点击:

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

excelvba

提问by MikeG

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

回答by Doug Glancy

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