![]() |
Wait for action
Hallo!
I want to make a macro that show a userform with a button. If the user have not clicked the button within 15 sec I want the code to continue. If the user click the button the code will end. Thanks for any help! Johan |
Wait for action
What closes the userform is the HIDE method. Normally you put the HIDE into the click function but you can put it anyplace in the code. You need to start a timer function when you open the form in an initialize routine. and stop the timer when you close the form. the Timer Procedure must be in a module, not in the userform. You also need to stop the timer if the button is pressed. below is the module code Sub test() UserForm1.Show Call nextsub End Sub Sub my_procedure() UserForm1.Hide Call nextsub End Sub ----------------------------------------- Put this code into the userform Sub Userform_Initialize() Application.OnTime Now + TimeValue("00:00:15"), "my_Procedure" End Sub Private Sub CommandButton1_Click() 'code to stop the timer if the button is pressed. Application.OnTime EarliestTime:=Now, _ Procedu="my_Procedure", Schedule:=False End Sub -- joel ------------------------------------------------------------------------ joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=157409 Microsoft Office Help |
Wait for action
Thanks for your help joel, however the code goes to Error and gives the
following message: Run-time error '1004': Metode 'OnTime' of Object'_Application' failed Any help on that? Thanks Johan joel skrev: What closes the userform is the HIDE method. Normally you put the HIDE into the click function but you can put it anyplace in the code. You need to start a timer function when you open the form in an initialize routine. and stop the timer when you close the form. the Timer Procedure must be in a module, not in the userform. You also need to stop the timer if the button is pressed. below is the module code Sub test() UserForm1.Show Call nextsub End Sub Sub my_procedure() UserForm1.Hide Call nextsub End Sub ----------------------------------------- Put this code into the userform Sub Userform_Initialize() Application.OnTime Now + TimeValue("00:00:15"), "my_Procedure" End Sub Private Sub CommandButton1_Click() 'code to stop the timer if the button is pressed. Application.OnTime EarliestTime:=Now, _ Procedu="my_Procedure", Schedule:=False End Sub -- joel ------------------------------------------------------------------------ joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=157409 Microsoft Office Help . |
Wait for action
Make sure the code matches exactly what appeas in the posting. I fully tested this code with 2003. The Procedure Name "My_Procedure" on the line and the procedure code in the Module must match. I tried to duplicate the error and cannot which make me believe the problem is a simple typo error. Try typing "application." without the double quotes (with a period at the end) and check in the pop up window to see in "ONTIME" appears. I want to see if all the libraries are installed on your PC. -- joel ------------------------------------------------------------------------ joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=157409 Microsoft Office Help |
All times are GMT +1. The time now is 04:57 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com