VBA如何使用变量字符串来调用变量或函数?

Sco*_*ott 1 excel vba excel-vba

我有一个名为"text1,text2,text2 ..."的表单输入,我有一个字符串数组来填充输入...

我想要的是......

text1.Value = Invoice.input(1)
text2.Value = Invoice.input(2)
text3.Value = Invoice.input(3)
Run Code Online (Sandbox Code Playgroud)

但这似乎很多打字我知道可以用一个简单的for循环来完成.

for loop = 1 To loop = 50 
 text+i.Value = Invoice.input(i)
next loop 
Run Code Online (Sandbox Code Playgroud)

我如何使用text + i来调用我实际上称为text1的var?

在进行Google搜索时,有些人说要使用Eval()函数,但这对我不起作用.

谢谢.

MiV*_*oth 5

这应该这样做:(或至少帮助)

Sub ControlName()
    Dim i As Long
    For i = 1 To 50
        UserForm1.Controls("text" & i).Value = Invoice.input(i)
    Next
End Sub
Run Code Online (Sandbox Code Playgroud)

  • + 1点上:-) (2认同)