我的一些组合框名称以“TBSum...”开头。目标是搜索所有包含此字符串“TBsum”的组合框,并使用 back_Color 和 fore_Color 为这些框着色。下面的代码不起作用,因为我不知道如何编写代码来搜索组合框名称中的字符串。请帮忙?提前谢谢。所有这些组合框都在“MultiPage1.Page6”上...
Private Sub MultiPage1_Enter()
Dim N As Long
Dim control_Object As Control
N = 1
back_Color = RGB(214, 233, 215)
fore_Color = RGB(0, 128, 0)
For Each control_Object In Me.Controls
If Me.Controls(N).Name = "TBSum" Then
Me.Controls(N).BackColor = back_Color
Me.Controls(N).ForeColor = fore_Color
End If
Next control_Object
End Sub
编辑
尚未工作,更新了以下代码。代码运行,没有错误。但没有结果。我不知道哪里出了问题。请帮忙。(已解决:更新以下代码以更正代码……基本上,我需要添加“对于 N=1……”)。现在更正代码:
Private Sub ColorCBSum()
N = 1
back_Color = &HFFFFC0
fore_Color = &H62331F
For Each control_Object In UserForm9.Controls
For N = 1 To UserForm9.Controls.Count - 1
If InStr(UserForm9.Controls(N).Name, "CBSum") = 1 Then
UserForm9.Controls(N).BackColor = back_Color
UserForm9.Controls(N).ForeColor = fore_Color
UserForm9.Controls(N) = Format(UserForm9.Controls(N), "#,##0;(#,##0)")
End If
Next N
Next control_Object
End Sub