UserForm Mouse click on form to close

MirageSF used Ask the Experts™

I have a Userform1 setup which works great, also using UserForm1_click() so when its clicked it shuts down which works....

Now I have added a application.wait (30 secs) setup and now clicking on the form no longer works as its waiting for the 30 second timer, is there a way to add a delay of 30 seconds before the form closes but still although clicking on the form to close it?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Older than dirt
Most Valuable Expert 2017
Distinguished Expert 2018
Instead of using Application.Wait, use the Wait30 sub I show here. In this code I have a command button calling the sub but you would probably need to call it from somewhere else.

Option Explicit
Private mbClicked As Boolean

Private Sub CommandButton1_Click()
End Sub

Private Sub UserForm_Click()
mbClicked = True
End Sub

Sub Wait30()
Dim dteTime1 As Date
Dim dteTime2 As Date

dteTime1 = Now
dteTime2 = Now + TimeValue("0:00:30")
    Do Until dteTime1 >= dteTime2
        If mbClicked Then
            Unload Me
            Exit Sub
        End If
        dteTime1 = Now()

End Sub

Open in new window


Oh, very nice and worked a treat thank you.
Martin LissOlder than dirt
Most Valuable Expert 2017
Distinguished Expert 2018

You're welcome and I'm glad I was able to help.

If you expand the “Full Biography” section of my profile you'll find links to some articles I've written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange MVE 2015
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2017

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial