• timeout userforms, message boxes, etc. (97/2000/2002)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » timeout userforms, message boxes, etc. (97/2000/2002)

    Author
    Topic
    #372626

    What is the easiest way to make a MsgBox or custom userform time out so that the form will
    automatically unload and the code continue executing in, say, 60 seconds if the user does not
    respond?

    Damon Ostrander

    Viewing 0 reply threads
    Author
    Replies
    • #596176

      If your form is named Userform1:

      In a normal module:

      Sub DismissIt()
      Unload UserForm1
      End Sub
      Sub ShowIt()
      UserForm1.Show
      MsgBox “Done!”
      End Sub

      In the forms module:

      Private Sub UserForm_Initialize()
      Application.OnTime Now + TimeValue(“00:00:05”), “dismissit”
      End Sub

      • #596544

        Thanks Jan,

        That was helpful. I had to add a bit of code to keep from getting an error if I cancelled the userform manually before the timeout occurred:

        Dim DismissTime As Date

        Private Sub CommandButton1_Click()
        Application.OnTime DismissTime, “dismissit”, schedule:=False
        Unload Me
        End Sub

        Private Sub UserForm_Initialize()
        DismissTime = Now + TimeValue(“00:00:05”)
        Application.OnTime DismissTime, “dismissit”
        End Sub

        Keep Excelling.

        Damon

    Viewing 0 reply threads
    Reply To: timeout userforms, message boxes, etc. (97/2000/2002)

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

    Your information: