Hi all,
I'm a bit perplexed as to why this code isn't working for me; especially considering how I've managed to get it working in other ways.
Basically; I want my workbook to auto-save and close after a period of inactivity (set at 30 seconds), which is defined in a module; using this code:
So using this I essentially have a pretty simple start and stop timer function. I then initialise the timer using the WorkBook_Open function.
Now, as my workbook is 95% user forms, command buttons and generically more 'interactive' than a normal spreadsheet, I need to find a way of resetting this timer whenever a user interacts with the interface, e.g. clicking a command button, changing the selection on a list, activating a new user form and whatever else I can think of.
I've tried adding the following lines to various command buttons, to which I thought 'theoretically' would work:
Unfortunately for me, this isn't working and the timer isn't being reset. I'm struggling to understand why as theoretically everything should work as anticipated.
If anyone could shed any light on this I would appreciate it greatly, or if anyone has any other smart ideas as to how I can reset the timer when a user interacts with a userform and such then please go ahead!
I was wondering myself if it would be possible to reset the timer when a cell on a sheet changes value (i.e. Cell A1 on Sheet "Activity" changes to "Clicked Log In", when the user clicks the login command button, or changes to "Clicked Raise Issue" when the user uses that command button etc.)
If anyone can spare a hand please do!
Thanks
I'm a bit perplexed as to why this code isn't working for me; especially considering how I've managed to get it working in other ways.
Basically; I want my workbook to auto-save and close after a period of inactivity (set at 30 seconds), which is defined in a module; using this code:
Code:
Dim DownTime As Date
Sub SetTimer()
DownTime = Now + TimeValue("01:00:00")
Application.OnTime EarliestTime:=DownTime, _
Procedure:="ShutDown", Schedule:=True
End Sub
Sub StopTimer()
On Error Resume Next
Application.OnTime EarliestTime:=DownTime, _
Procedure:="ShutDown", Schedule:=False
End Sub
Sub ShutDown()
Application.DisplayAlerts = False
With ThisWorkbook
.Saved = True
.Close
End With
End Sub
So using this I essentially have a pretty simple start and stop timer function. I then initialise the timer using the WorkBook_Open function.
Now, as my workbook is 95% user forms, command buttons and generically more 'interactive' than a normal spreadsheet, I need to find a way of resetting this timer whenever a user interacts with the interface, e.g. clicking a command button, changing the selection on a list, activating a new user form and whatever else I can think of.
I've tried adding the following lines to various command buttons, to which I thought 'theoretically' would work:
Code:
Private Sub cmd_login_Click()
Call StopTimer
Call StartTimer
'Launch Login Prompt'
frm_login.Show
End Sub
Unfortunately for me, this isn't working and the timer isn't being reset. I'm struggling to understand why as theoretically everything should work as anticipated.
If anyone could shed any light on this I would appreciate it greatly, or if anyone has any other smart ideas as to how I can reset the timer when a user interacts with a userform and such then please go ahead!
I was wondering myself if it would be possible to reset the timer when a cell on a sheet changes value (i.e. Cell A1 on Sheet "Activity" changes to "Clicked Log In", when the user clicks the login command button, or changes to "Clicked Raise Issue" when the user uses that command button etc.)
If anyone can spare a hand please do!
Thanks