Joh*_*n M 3 excel vba excel-2007 excel-vba
我想替换以下内容:
txt1.Text = ""
txt2.Text = ""
txt3.Text = ""
txt4.text = ""
...continues for quite awhile
Run Code Online (Sandbox Code Playgroud)
附:
Dim cCont As Control
For Each cCont In Me.Controls
If TypeName(cCont) = "TextBox" Then
'reset textbox value
???
End If
Next cCont
Run Code Online (Sandbox Code Playgroud)
如何使用通用"控件"来引用文本框?
你已经掌控了cCont.
Dim cCont As Control
For Each cCont In Me.Controls
If TypeOf cCont Is MSForms.TextBox Then
cCont.Text = "hi"
MsgBox cCont.Name
End If
Next
Run Code Online (Sandbox Code Playgroud)
如果您对未Text从IntelliSense 获取属性的事实感到困惑,只需将其Control转换为更加派生的类型:
Dim cCont As Control
For Each cCont In Me.Controls
If TypeOf cCont Is MSForms.TextBox Then
Dim cText As MSForms.TextBox
Set cText = cCont
cText.Text = "hi"
MsgBox cText.Name
End If
Next
Run Code Online (Sandbox Code Playgroud)
这将使用早期绑定而不是后期绑定,您将获得代码建议.
| 归档时间: |
|
| 查看次数: |
11396 次 |
| 最近记录: |