Dim RTB As RichTextBox
If RTB Is Nothing Then
    MsgBox "have no richtextbox"
Else
    MsgBox "have richtextbox"
End If

解决方案 »

  1.   

    Dim RTB As RichTextBox
    If RTB Is Nothing Then
        MsgBox "have no richtextbox"
    Else
        MsgBox "have richtextbox"
    End If
      

  2.   

    如果不存在的话,编译会出错的。
    或者,你可以长是对他进行操作,通过错误处理来判断是否存在。
    on error go to e
      mycontrol.top=1
    ....
    e:
      if err.number=xxxxx then 
        ishavecontrol=false
        resume next
      else
        .....
      

  3.   

    GetObject([PathName] as string,[ClassName] as String)Returns a reference to an object provided by an ActiveX component
      

  4.   

    Returns a reference to an object provided by an ActiveX component.SyntaxGetObject([pathname] [, class])
      

  5.   

    请看:
    Private Function FindRtext() As Boolean
    Dim CtlX As Control
    For Each CtlX In Controls
        If TypeName(CtlX) = "RichTextBox" Then
            FindRtext = True
        End If
    Next
    End Function
      

  6.   

    Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hwndParent As Long, ByVal hwndChildAfter As Long, ByVal lpszClass As String, ByVal lpszWindow As String) As Long
    可以按類名 或 控件的標題找
      

  7.   

    for i=1 to me.Controls.Count
        if me.Controls(i-1).name="RichTextBox1" then
            ControlExit = True
            exit for 
        end if
    next
      

  8.   

    zhengchong(zxc) 
    这只能看当前窗口中有没有指定控件,如果程序发行时没有带上这个控件,而程序中使用了这个控件,则程序可能无法执行到这一步。
      

  9.   

    dim rechtextbox1 as object
    for each rechtextbox1 in me.controls
        if typeof rechtextbox1 is richtextbox then
               msgbox "richtextbox is exists"
        endif
    next
      

  10.   

    Dim X As Control
    For Each X In Form1.Controls
        If X.Name <> Richtextbox Then
            MsgBox "ok"
        End If
    Next X
      

  11.   

    zhengchong
    我动态的加载一个richtextbox,用你的代码可以判断存在,可是但当又将其,卸掉,再判断是否存在,为何还判断它存在呢?
      

  12.   

    如果richtextbox是控件数组那怎么办?如何对其中的任一个进行判断?