简体   繁体   English

Excel VBA 获取相邻的userform控件值

[英]Excel VBA Get adjacent userform control value

I have a userform with several rows of textboxes.我有一个带有几行文本框的用户表单。 As I loop through the controls, I'm concatenating the textbox values for a final string.当我遍历控件时,我将文本框值连接为最终字符串。 Rather than looping through every textbox, I am only looping through the first textbox in the row and trying to assign a value to a variable with the replace method.我不是遍历每个文本框,而是遍历行中的第一个文本框,并尝试使用replace方法为变量赋值。

What I've tried: TBvalue = Replace(ctl.Name, "Textbox1", "Textbox2")我试过的: TBvalue = Replace(ctl.Name, "Textbox1", "Textbox2")

followed by TBvalue2 = OnboardingLogForm.TBvalue.value其次是TBvalue2 = OnboardingLogForm.TBvalue.value

Also tried: TBvalue = OnboardingLogForm.Textbox & i.value when iterating with i还尝试过: TBvalue = OnboardingLogForm.Textbox & i.value使用 i 进行迭代时

How can I get the values of other textboxes without statically referring to them?如何在不静态引用其他文本框的情况下获取它们的值?

Found an answer.找到了答案。 Thanks for your help.谢谢你的帮助。

Me.Controls("TextBox" & i).value

Or, if there's any number order to your control names, you can try:或者,如果您的控件名称有任何数字顺序,您可以尝试:

For Each ctl In Userform1.MultiPage1.Pages(0).Controls
    blah = Me.Controls(Replace(ctl.Name, "TextBox1", "TextBox2")).value
Next

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM