VBA Refer to TextBox or Label using a loop
问题 I am trying to replace the following: txt1.Text = "" txt2.Text = "" txt3.Text = "" txt4.text = "" ...continues for quite awhile With: Dim cCont As Control For Each cCont In Me.Controls If TypeName(cCont) = "TextBox" Then 'reset textbox value ??? End If Next cCont How do I refer to the textbox using the generic 'Control'? 回答1: You already have your control in cCont. Dim cCont As Control For Each cCont In Me.Controls If TypeOf cCont Is MSForms.TextBox Then cCont.Text = "hi" MsgBox cCont.Name