我正在制作一个带有很多文本框输入的程序,稍后再提交,我想将文本框名称分配为变量,并使用循环将文本框的名称从Texbox1递增到Textbox 20 < / p>
Dim Y As Integer
Dim X As String
Dim I As Integer
For I = 1 To 20
X = "TextBox" & Y
X.Value = ""
Next I
答案 0 :(得分:2)
我认为您正在寻找类似的东西(我是UserForm的名称):
Dim x As String
Dim i As Integer
For i = 1 To 20
x = Me.Controls("TextBox" & i).Value
Next i
答案 1 :(得分:1)
使用在线资源(https://www.ozgrid.com/VBA/control-loop.htm)
您可以遍历它们而不必添加变量名:
Private Sub UserForm_Initialize()
Dim cCont As control
For Each cCont In Me.Controls
cCont.Value = "foo"
Next cCont
End Sub