本示例使用 For Each...Next 语句搜寻集合中的所有成员的 Text 属性,查找“Hello”字符串。示例中,MyObject 是面向文本的对象,并且是 MyCollection 集合的成员,这两个名字只是为示范目的而使用的通用名称而已。Dim Found, MyObject, myForm
Found = False   ' 设置变量初始值。
For Each MyObject In myForm' 对每个成员作一次迭代。
   If MyObject.Text = "Hello" Then   ' 如果 Text 属性值等于“Hello”。
      Found = True   ' 将变量 Found 的值设成 True。
      Exit For   ' 退出循环。
   End If
Next

解决方案 »

  1.   

    Dim cc As Control
        
        For Each cc In Controls
            If cc.Container.Name = "Frame1" Then
                
            End If
        Next
      

  2.   

    For Each cc In Controls
            If cc.Container.Name = "Frame1" Then
                If (TypeOf cc Is TextBox) Or (TypeOf cc Is CheckBox) Then
                    ' your code
                End If
            End If
        Next
      

  3.   

    Dim ctl As ControlFor Each ctl In Me.Controls
        If TypeName(ctl.Container) = "Frame" Then
            Debug.Print ctl.Name
        End If
    Next
      

  4.   

    Dim ctl As ControlFor Each ctl In Me.Controls
        If TypeName(ctl.Container) = "Frame" Then
            Select Case UCase$(TypeName$(ctl))
                Case "TEXTBOX"
                    Debug.Print ctl.Name
                Case "CHECKBOX"
                    Debug.Print ctl.Name
            End Select
        End If
    Next