Private Sub Command1_Click()
Dim objPIC As ControlFor Each objPIC In Me.Controls
    If TypeName(objPIC) = "Text1" Then
        MsgBox "Exist!"
        Exit Sub
    End If
Next objPICMsgBox "Do Not Exist !"
End Sub

解决方案 »

  1.   

    检测是否有 com1 方法一样,把Text1 替换就行或者:Private Sub Command1_Click()
    Dim objPIC As ControlFor Each objPIC In Me.Controls
        If TypeName(objPIC) = "Text1" or TypeName(objPIC) = "com1" Then
            MsgBox "Exist!"
            Exit Sub
        End If
    Next objPICMsgBox "Do Not Exist !"
    End Sub
      

  2.   

    Private Sub Command1_Click()
    Dim tt As ControlFor Each tt In Me.Controls
      If TypeOf tt Is TextBox Then
         If tt.Name = Text1 Then MsgBox "Exist!": Exit Sub
      End If
      If TypeOf tt Is CommandButton Then
         If tt.Name = Command1 Then MsgBox "exist!": Exit Sub
      End If
    Next tt
    MsgBox "Do Not Exist !"
    End Sub
      

  3.   

    danielinbiti(金) 的解法才是正解!
    wxy_xiaoyu(然也) 的typename显示的只是text1的类型而已。