如何使用变量引用用户窗体的复选框 [英] How do I reference the checkbox of the userform with a variable

查看:92
本文介绍了如何使用变量引用用户窗体的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何使用变量引用用户窗体的复选框吗?

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

我必须选中近40到50个复选框。但是像这样写40到50条语句很耗时,而且代码也更大。

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.

所以我有点想遍历它们:

So I was kinda thinking to loop through them:

 For i = 1 To 50 
   UserForm1.checkbox & i .Value
 Next i

类似的东西。我找不到太多,但最后找到了。这是链接 http://www.ozgrid.com/forum/showthread.php ?t = 43358 ,答案就是这样,

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=43358 and the answer was like these,

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.

推荐答案

UserForm1.Controls("Checkbox" & i).Value 

这篇关于如何使用变量引用用户窗体的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆