Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Close automatically a userform
How to close a userform if no entry is made within 10 seconds? Kindly help
with an appropriate macro. |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
Close automatically a userform
Code goes into the user form's code section, not the workbook itself. For
the examples, the user form's name is UserForm1 1st method: if no entry made for 10 seconds, form closes, but any entry made causes it to remain open no matter how long it takes to finish entries. Option Explicit Public myUserFormFlag As Boolean Private Sub UserForm_Activate() Dim startTimer As Long myUserFormFlag = False startTimer = Timer Do While myUserFormFlag = False DoEvents If Timer (startTimer + 10) Then UserForm1.Hide Exit Do End If Loop End Sub Private Sub ComboBox1_Change() myUserFormFlag = True End Sub Private Sub TextBox1_Change() myUserFormFlag = True End Sub The 'secret' in that is that you need to add the line myUserFormFlag = True at the start of any action event for any of your controls on the form. Then when any one of them is used, the timing tests stop and the form stays open. A second method: this one will keep the form open as long as someone does something, as type a letter into a text box, at least once each 10 seconds, but once no action has taken place on the form at all for 10 seconds, it closes, even with partially completed text entries: Option Explicit Public startTimer As Long Private Sub UserForm_Activate() startTimer = Timer Do While Timer < (startTimer + 10) DoEvents Loop UserForm1.Hide End Sub Private Sub ComboBox1_Change() startTimer = Timer End Sub Private Sub TextBox1_Change() startTimer = Timer End Sub With this second one, the 'secret' is in resetting startTimer when any control is changed/used on the form. So the 10-second clock gets restarted any time there is activity on the form. I showed how to do it with a form with a ComboBox and a TextBox on it, just do much the same for any/all controls on the form and you should be fine. "FARAZ QURESHI" wrote: How to close a userform if no entry is made within 10 seconds? Kindly help with an appropriate macro. |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
Close automatically a userform
Thanx bro
Shall try out the same. Can u help me out one another problem? I want a timestamp to be appearing for each and every entry in column A in corresponding column B. The problem is that whether the entry is made as punched/typed or pased. In other words if I paste an array/range in a single Ctrl+V or Enter stroke, on cells A1:A10 I want the cells B1:B10 to be reflecting a time stamp on every cell. "JLatham" wrote: Code goes into the user form's code section, not the workbook itself. For the examples, the user form's name is UserForm1 1st method: if no entry made for 10 seconds, form closes, but any entry made causes it to remain open no matter how long it takes to finish entries. Option Explicit Public myUserFormFlag As Boolean Private Sub UserForm_Activate() Dim startTimer As Long myUserFormFlag = False startTimer = Timer Do While myUserFormFlag = False DoEvents If Timer (startTimer + 10) Then UserForm1.Hide Exit Do End If Loop End Sub Private Sub ComboBox1_Change() myUserFormFlag = True End Sub Private Sub TextBox1_Change() myUserFormFlag = True End Sub The 'secret' in that is that you need to add the line myUserFormFlag = True at the start of any action event for any of your controls on the form. Then when any one of them is used, the timing tests stop and the form stays open. A second method: this one will keep the form open as long as someone does something, as type a letter into a text box, at least once each 10 seconds, but once no action has taken place on the form at all for 10 seconds, it closes, even with partially completed text entries: Option Explicit Public startTimer As Long Private Sub UserForm_Activate() startTimer = Timer Do While Timer < (startTimer + 10) DoEvents Loop UserForm1.Hide End Sub Private Sub ComboBox1_Change() startTimer = Timer End Sub Private Sub TextBox1_Change() startTimer = Timer End Sub With this second one, the 'secret' is in resetting startTimer when any control is changed/used on the form. So the 10-second clock gets restarted any time there is activity on the form. I showed how to do it with a form with a ComboBox and a TextBox on it, just do much the same for any/all controls on the form and you should be fine. "FARAZ QURESHI" wrote: How to close a userform if no entry is made within 10 seconds? Kindly help with an appropriate macro. |
#4
Posted to microsoft.public.excel.misc
|
|||
|
|||
Close automatically a userform
I believe Gord Dibben is trying to assist you with that in another
discussion. Best to just continue that discussion there rather than mixing things up and continuing here. I will look at that and if I can add to the discussion, I will. "FARAZ QURESHI" wrote: Thanx bro Shall try out the same. Can u help me out one another problem? I want a timestamp to be appearing for each and every entry in column A in corresponding column B. The problem is that whether the entry is made as punched/typed or pased. In other words if I paste an array/range in a single Ctrl+V or Enter stroke, on cells A1:A10 I want the cells B1:B10 to be reflecting a time stamp on every cell. "JLatham" wrote: Code goes into the user form's code section, not the workbook itself. For the examples, the user form's name is UserForm1 1st method: if no entry made for 10 seconds, form closes, but any entry made causes it to remain open no matter how long it takes to finish entries. Option Explicit Public myUserFormFlag As Boolean Private Sub UserForm_Activate() Dim startTimer As Long myUserFormFlag = False startTimer = Timer Do While myUserFormFlag = False DoEvents If Timer (startTimer + 10) Then UserForm1.Hide Exit Do End If Loop End Sub Private Sub ComboBox1_Change() myUserFormFlag = True End Sub Private Sub TextBox1_Change() myUserFormFlag = True End Sub The 'secret' in that is that you need to add the line myUserFormFlag = True at the start of any action event for any of your controls on the form. Then when any one of them is used, the timing tests stop and the form stays open. A second method: this one will keep the form open as long as someone does something, as type a letter into a text box, at least once each 10 seconds, but once no action has taken place on the form at all for 10 seconds, it closes, even with partially completed text entries: Option Explicit Public startTimer As Long Private Sub UserForm_Activate() startTimer = Timer Do While Timer < (startTimer + 10) DoEvents Loop UserForm1.Hide End Sub Private Sub ComboBox1_Change() startTimer = Timer End Sub Private Sub TextBox1_Change() startTimer = Timer End Sub With this second one, the 'secret' is in resetting startTimer when any control is changed/used on the form. So the 10-second clock gets restarted any time there is activity on the form. I showed how to do it with a form with a ComboBox and a TextBox on it, just do much the same for any/all controls on the form and you should be fine. "FARAZ QURESHI" wrote: How to close a userform if no entry is made within 10 seconds? Kindly help with an appropriate macro. |
#5
Posted to microsoft.public.excel.misc
|
|||
|
|||
Close automatically a userform
Hi,
No doubt Gord was handling the matter quite great but has given up. You can reply me in that question panel as well. "JLatham" wrote: I believe Gord Dibben is trying to assist you with that in another discussion. Best to just continue that discussion there rather than mixing things up and continuing here. I will look at that and if I can add to the discussion, I will. "FARAZ QURESHI" wrote: Thanx bro Shall try out the same. Can u help me out one another problem? I want a timestamp to be appearing for each and every entry in column A in corresponding column B. The problem is that whether the entry is made as punched/typed or pased. In other words if I paste an array/range in a single Ctrl+V or Enter stroke, on cells A1:A10 I want the cells B1:B10 to be reflecting a time stamp on every cell. "JLatham" wrote: Code goes into the user form's code section, not the workbook itself. For the examples, the user form's name is UserForm1 1st method: if no entry made for 10 seconds, form closes, but any entry made causes it to remain open no matter how long it takes to finish entries. Option Explicit Public myUserFormFlag As Boolean Private Sub UserForm_Activate() Dim startTimer As Long myUserFormFlag = False startTimer = Timer Do While myUserFormFlag = False DoEvents If Timer (startTimer + 10) Then UserForm1.Hide Exit Do End If Loop End Sub Private Sub ComboBox1_Change() myUserFormFlag = True End Sub Private Sub TextBox1_Change() myUserFormFlag = True End Sub The 'secret' in that is that you need to add the line myUserFormFlag = True at the start of any action event for any of your controls on the form. Then when any one of them is used, the timing tests stop and the form stays open. A second method: this one will keep the form open as long as someone does something, as type a letter into a text box, at least once each 10 seconds, but once no action has taken place on the form at all for 10 seconds, it closes, even with partially completed text entries: Option Explicit Public startTimer As Long Private Sub UserForm_Activate() startTimer = Timer Do While Timer < (startTimer + 10) DoEvents Loop UserForm1.Hide End Sub Private Sub ComboBox1_Change() startTimer = Timer End Sub Private Sub TextBox1_Change() startTimer = Timer End Sub With this second one, the 'secret' is in resetting startTimer when any control is changed/used on the form. So the 10-second clock gets restarted any time there is activity on the form. I showed how to do it with a form with a ComboBox and a TextBox on it, just do much the same for any/all controls on the form and you should be fine. "FARAZ QURESHI" wrote: How to close a userform if no entry is made within 10 seconds? Kindly help with an appropriate macro. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
default template (book.xlt) doesn't close | Excel Discussion (Misc queries) | |||
close button does not close | Excel Discussion (Misc queries) | |||
automatically close hyperlink with back button | Excel Worksheet Functions | |||
closing 1 file at a time | Excel Discussion (Misc queries) | |||
Excel shoud not close all active books when clicking close button | Excel Discussion (Misc queries) |