如果把控件数组Text(1)....Text(10)代替TEXT1.......TEXT10,就可以用以下代码:
for i =1 to 10
range("A"& i ) =text(i).text
next
Dim obj as object
for each obj in me
if TypeName(obj)="TextBox" Then
range("A" & mid(obj.Name,instrrev(obj.Name,"x")+1))=obj.Text
next obj
理论上可以精确匹配所有的文本框
Public Sub DSA()
Dim iBxs As New Collection, i
With Sheet1
iBxs.Add .TextBox1
iBxs.Add .TextBox2
iBxs.Add .TextBox3
'……
For i = 1 To iBxs.Count
.Range("A" & i).Value = iBxs(i).Text
Next
End With
End Sub
用callbyname:
for i =1 to 10
range("A"& i ) = callbyname(me,"Text"&i,VbGet).Text
next
range("A"& i ) = Controls("Text" & i).Text