[英]Formatting Multiple Controls in an Excel UserForm using VBA
我四处打猎,已经到了我几乎被分类但不能完全完成的地步。
我有以下内容:
Sub Formats()
'Form Setup
'----------------
With AuditForm
.BackColor = Grey4
.BorderColor = Grey1
.Font.Name = "Arial"
.ForeColor = Grey1
.SpecialEffect = 1
End With
For Each ctrl In AuditForm.Controls
If TypeName(ctrl) = "TextBox" Then
ctrl.BackColor = White
ctrl.BorderColor = Grey1
ctrl.SpecialEffect = 1
ctrl.BorderStyle = 1
ctrl.Font.Name = "Arial"
ElseIf TypeName(ctrl) = "Frame" Then
ctrl.BackColor = Grey4
ctrl.BorderColor = Grey1
ctrl.SpecialEffect = 1
ctrl.BorderStyle = 1
ctrl.Font.Name = "Arial"
ctrl.ForeColor = Grey1
ctrl.Font.Bold = True
ElseIf TypeName(ctrl) = "Label" Then
ctrl.BackColor = Grey4
ctrl.BorderColor = Grey4
ctrl.SpecialEffect = 1
ctrl.BorderStyle = 1
ctrl.Font.Name = "Arial"
ctrl.ForeColor = Grey1
ctrl.Font.Bold = True
ElseIf TypeName(ctrl) = "ComboBox" Then
ctrl.BackColor = White
ctrl.BorderColor = Grey1
ctrl.SpecialEffect = 1
ctrl.BorderStyle = 1
ctrl.Font.Name = "Arial"
ctrl.ShowDropButtonWhen = fmShowDropButtonWhenFocus
ctrl.Style = fmStyleDropDownList
End If
Next ctrl
End Sub
我在代码中有我需要的每种控件类型,但我只想更改:
For Each ctrl In AuditForm.Controls
引用打开的任何用户表单。 我试过For Each ctrl In me.controls
但这似乎出错了。 另一种方法是为我的文档中的每个用户窗体复制上面的块,这看起来很乱。
任何帮助将不胜感激。
谢谢,
账单
比尔,只需将您的 ctrl 变量声明为 MSForms.Control
Dim ctrl As MSForms.Control
For Each ctrl In Me.Controls
' it works !
Next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.