UserForm Time limit

Chicken6

New Member
Joined
Dec 30, 2012
Messages
15
How can I have a userform open for only three minutes before it unloads (saving what was inputted during that time)?

I have a form where the users only have 3min to finish (a Spatial Psych test). I have tried the following code but it doesn't work. (just experimenting with 10 seconds for now.)

I haven't put all the questions in the form yet. I will when I know I can get the timer to work. If not, they get to do it on paper!

Code:
'module

Option Explicit

Private Sub KillTheForm()
ActiveWorkbook.Save
Unload UserFormSpatial
End Sub



Code:
'Userform object

Option Explicit

Private Sub UserFormSpatial_Activate()
Application.OnTime (Now + TimeValue("00:00:10")), "KillTheForm"
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
like this

module:
Code:
Public Sub UnloadIt()
    Unload UserForm1
End Sub


Sub test()
UserForm1.Show vbModeless
End Sub


userform:
Code:
[CODE]Private Sub UserForm_Activate()
Application.OnTime Now + TimeValue("00:00:05"), "UnloadIt"
End Sub

or

Code:
Private Sub UserForm_Initialize()
Application.OnTime Now + TimeValue("00:00:05"), "UnloadIt"
End Sub

both of those methods are working
 
Upvote 0
Hey Hippiehacker,
thanks for the speedy reply!

Tried it out, but not working. However I have a feeling it has something to do with the fact I am using a Mac. I am going to test it out on the PC in the lab tomorrow, and will let you know!

Thanks heaps!
:)
 
Upvote 0
Hey HH,
thanks for the link, didn't see that one! I tried out both the delay and the loop methods, with no success. I reckon it's something to do with my machine. I am also using Excel 2011 on a Mac. However I won't get concerned until your method doesn't work on the lab machines, which are all PCs, and upon which the experiment will run. Will let you know tomoz.

Thanks again!
C6
 
Upvote 0
Yes!
it worked on the PC in the lab. I think it was my error rather than the OS. From your code I had changed the name of the UserForm in the UserForm code, to match the name (UserForm1) rather than just leave it as UserForm. I picked up the error when I just copied and pasted your code without change and it worked.

Thanks again HH

:)
 
Upvote 0

Forum statistics

Threads
1,215,447
Messages
6,124,907
Members
449,194
Latest member
JayEggleton

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top