• How to determine if a UserForm is open (2002 SP1)

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » How to determine if a UserForm is open (2002 SP1)

    Author
    Topic
    #375115

    I want to write some code to check if a UserForm is open,
    but using the following doesn’t work:

    If [formname].Visible = False Then
    [run code here]
    End If

    What’s the best answer?

    Many thanks

    Mark Hartt-Palmer

    Viewing 2 reply threads
    Author
    Replies
    • #609048

      Check the Forms collection.

    • #609098

      I would love to know the answer to this, as well as to the larger question of how to tell if you have multiple instances of Word (or of a Word form) running invisibly in the background. Checking to see if a particular form is visible doesn’t work, because a form may not be visible because it is not loaded.

      For example:
      (first create UserForm1 with its ShowModal set to True, then run the following macro:)
      Sub ShowMyForm()
      UserForm1.Show

    • #609180

      Howard’s suggestion is cryptic, and the documention is poor, but in Word 2000, this will give the expected results:

      Sub DoesUFLive()
      Debug.Print UserFormLoaded("UserForm1")
      Load UserForm1
      Debug.Print UserFormLoaded("UserForm1")
      UserForm1.Show vbModeless
      Debug.Print UserFormLoaded("UserForm1")
      UserForm1.Hide
      Debug.Print UserFormLoaded("UserForm1")
      Unload UserForm1
      Debug.Print UserFormLoaded("UserForm1")
      Set UserForm1 = Nothing
      Debug.Print UserFormLoaded("UserForm1")
      End Sub
       
      Function UserFormLoaded(strUFName As String) As Boolean
      ' This is a case sensitive comparison
      If UserForms.Count > 0 Then
          Dim intCounter As Integer
          For intCounter = 1 To UserForms.Count
              If UserForms(intCounter - 1).Name = strUFName Then
                  UserFormLoaded = True
                  Exit Function
              End If
          Next
      End If
      UserFormLoaded = False
      End Function

      Results:

      False
      True
      True
      True
      False
      False

      Hope this helps.

    Viewing 2 reply threads
    Reply To: How to determine if a UserForm is open (2002 SP1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: