Dim x   As VB.Control
For Each x In Me.Controls
        if x.Container.name="Frame" then
        If VBA.VarType(VBA.CallByName(Me, x.Name, VbGet)) = vbObject Then                    '控件数组
              Debug.Print x.text & ".Item(" & x.Index & ")"
        Else
              Debug.Print x.text
        End If
        end if
Next x

解决方案 »

  1.   

    假如控件没有text属性会出错,我没有捕捉错误
      

  2.   

    Private Sub Command1_Click()
        Dim aa As VB.Control
        For Each aa In Me.Controls
            If aa.Container Is Frame1 Then
                If TypeName(aa) = "TextBox" Then Debug.Print aa.Text
            End If
        Next
    End Sub我的也可以。原理跟阿甘的一样
      

  3.   

    阿甘,你确认X.TEXT属性是有效且能用的吗?
    为什么在我的机器上说ERROR:对象不支持这个属性或方法???fuxc(Michael) 也报告同样的错误!!
      

  4.   

    假如控件没有text属性会出错,我没有捕捉错误比如label控件就没有text属性
      

  5.   

    可是我的Frame上只有TextBox控件,TextBox控件绝对有Text属性呀……
      

  6.   

    加上“On Error Resume Next”Private Sub Command1_Click()
        Dim aa As VB.Control
        
        On Error Resume Next
        
        For Each aa In Me.Controls
            If aa.Container Is Frame1 Then
                If TypeName(aa) = "TextBox" Then Debug.Print aa.Text
            End If
        Next
    End Sub
      

  7.   

    fuxc(Michael) 的代码不会报告错误,注:CommandButton控件不能放在Frame控件上。
      

  8.   

    Private Sub Command1_Click()
    Dim x   As VB.Control
    On Error Resume Next
    For Each x In Me.Controls
            If x.Container.Name = "Frame1" Then
            If VBA.VarType(VBA.CallByName(Me, x.Name, VbGet)) = vbObject Then
                  Debug.Print x.Text & ".Item(" & x.Index & ")"
            Else
                  Debug.Print x.Text
            End If
            End If
    Next x
    End Sub加上忽略错误不就全部Ok啊?
    hehe