从字符串 (VBA) 中引用 Excel 用户窗体控件名称值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24083717/
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-08 18:17:39  来源:igfitidea点击:

Referencing Excel Userform Control Name Value From String (VBA)

excelvba

提问by Thomas

Typically when referencing a userform control value in Excel VBA I would enter something to the effect of radiobutton.value

通常在 Excel VBA 中引用用户窗体控件值时,我会输入一些影响 radiobutton.value 的内容

However, I want to be able to use a string as the name of the user control. The idea behind this would be to dynamically be able to generate the control name and reference a value from it.

但是,我希望能够使用字符串作为用户控件的名称。这背后的想法是能够动态地生成控件名称并从中引用一个值。

For example I may want to reference ctradiobutton.value one time, and etradiobutton.value the next, these controls already exist on the form, I just want to reference a different name of the control from a string created on the current iteration.

例如,我可能想引用 ctradiobutton.value 一次,然后引用 eradiobutton.value,这些控件已经存在于表单中,我只想引用与当前迭代中创建的字符串不同的控件名称。

回答by SWa

Like this (where Meis the UserForm)

像这样(Me用户窗体在哪里)

Me.Controls("TextBox1").Value