(1)自定义函数
Public Function LetTxtValues(ByVal strName As String, _
ByVal strTemp as String) As Boolean
On Error GoTo 0
Dim objObject As Object
'遍历窗体上对象
For Each objObject In objForm
If TypeOf objObject Is TextBox Then
If objObject.Name = strName Then
objObject.Text = strTemp
End If
End If
Next
Private Sub Command1_Click()
Dim a As String
Dim i As Integer
For i = 1 To 2
a = "Text" & i
Dim myTxt As TextBox
Set myTxt = Me.Controls(a)
myTxt.Text = "Hello" & i
Next
End Sub
楼主的意思是用一个变量名代替控件吧:
code:
Private Sub Command1_Click()
Dim s As String
s = "text1"
Dim a As TextBox
Set a = CallByName(Me, s, VbGet)
a.Text = "hello"
End Sub
是这个意思么^_^