VBA 使用循环引用文本框或标签
我正在尝试替换以下内容:
txt1.Text = ""
txt2.Text = ""
txt3.Text = ""
txt4.text = ""
...continues for quite awhile
替换为:
Dim cCont As Control
For Each cCont In Me.Controls
If TypeName(cCont) = "TextBox" Then
'reset textbox value
???
End If
Next cCont
如何使用通用“控件”引用文本框?
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'?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经在 cCont 中拥有控制权。
如果您对没有从 IntelliSense 获取
Text
属性感到困惑,只需将Control
转换为更派生的类型:这将使用早期绑定而不是后期绑定,您将获得代码建议。
You already have your control in cCont.
If you're confused by the fact you don't get the
Text
property from IntelliSense, just cast theControl
to a more derived type:This will use early binding instead of late binding, and you'll get your code suggestions.