Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    May 2002
    Location
    Colorado, USA
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    New Lounger
    Join Date
    May 2002
    Location
    Colorado, USA
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •