User Inactivity Auto-Close

himalayan

New Member
Joined
Nov 12, 2014
Messages
5
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:

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
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,215,084
Messages
6,123,021
Members
449,092
Latest member
ikke

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