Macro Wont Run When cell is selected ... Application.OnTime EarliestTime:=DownTime

lance01

New Member
Joined
Dec 12, 2013
Messages
15
Hi all,
I have a workbook that we use in work in work with a timer function that shuts down the workbook when the workbook hasn't been used for 15 minutes.
However, if my peers select a cell and go into edit mode then no macros run and then they go home so no one can edit it.
Is there a modification or a different VBA code that I can use that closes the workbook down without saving after 15 minutes even if a cell is in edit mode???? Pulling my hair out over this one. I've pasted my current code below.

In a module
Dim DownTime As Date
Sub SetTimer()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' This is where the timer is set to autoclose without saving
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DownTime = Now + TimeValue("00:015: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()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'This is where the timer is set to autoclose without saving, chage false to true to save when closing
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Application.DisplayAlerts = False
'Application.ScreenUpdating = False


With ThisWorkbook
.Saved = False
.Close
End With

End Sub




In the workbook area
Private Sub Workbook_Open()

Call SetTimer


End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call StopTimer
End Sub
Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
Call StopTimer
Call SetTimer
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Excel.Range)
Call StopTimer
Call SetTimer

End Sub




THANK YOU!!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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