on error resume next
Dim ctl As Control
    For Each ctl In form1.Controls
        ctl.BackColor = vbRed
    Next

解决方案 »

  1.   

    uguess(uguess):谢啦,能不能除了其中的几个控件外其它的都是同一个背景色呢? 
      

  2.   

    On Error Resume Next
    Dim ctl As Control
        For Each ctl In Form1.Controls
            
            Select Case ctl.Name
            Case "text1"
                ctl.BackColor = vbGreen
            Case "label1"
                ctl.BackColor = vbBlue
            Case Else
                ctl.BackColor = vbRed
            End Select
        Next
      另外,要给分的哦!!
      

  3.   

    Private Sub Command1_Click()
    On Error Resume Next
    Dim ctl As Control
        For Each ctl In Form1.Controls
            If ctl.Name <> "Command1" And ctl.Name <> "Label1" Then
                ctl.BackColor = vbRed
                Debug.Print ctl.Name
            End If
        NextEnd Sub