vba 如何使用变量引用用户表单的复选框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7966611/
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
How do I reference the checkbox of the userform with a variable
提问by niko
Could anyone tell me how to reference a checkbox of the userform with a variable?
谁能告诉我如何使用变量引用用户表单的复选框?
For example I have something like these,
例如我有这样的东西,
if UserForm1.checkbox1.Value
if UserForm1.checkbox2.Value
if UserForm1.checkbox3.Value
I have to check nearly 40 to 50 checkboxes. But writing the 40 to 50 statements like these is time consuming and also makes a bigger code.
我必须检查近 40 到 50 个复选框。但是像这样编写 40 到 50 条语句既费时又会生成更大的代码。
So I was kinda thinking to loop through them:
所以我有点想遍历它们:
For i = 1 To 50
UserForm1.checkbox & i .Value
Next i
Something like that. I didn't find too much but I found it at the end. This is the link http://www.ozgrid.com/forum/showthread.php?t=43358and the answer was like these,
类似的东西。我没有找到太多,但我最后找到了。这是链接http://www.ozgrid.com/forum/showthread.php?t=43358答案是这样的,
UserForm1.Shapes("Checkbox" & i).Value
But it isn't working. Does any one know the way to do it? Is it possible? Any help is greatly appreciated.
但它不起作用。有谁知道如何做到这一点?是否可以?任何帮助是极大的赞赏。
回答by Tim Williams
UserForm1.Controls("Checkbox" & i).Value