I have a worksheet with an inactive timer that checks for user activity on the worksheet. However, I changed the method of how data is entered to a userform and now when a user opens the form I built it counts the time in the form as inactivity on the worksheet. How to fix my timer to incorporate my entry from.
Below is my timer code:
in Thisworkbook
in Module
Below is my timer code:
in Thisworkbook
VBA Code:
Private Sub Workbook_Open()
MsgBox ("The data entry log is set to save and close in 5 minutues of inactivity")
Call StartClock
End Sub
Private Sub Workbook_SheetCalculate(ByVal sh As Object)
Call StopClock
Call StartClock
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call StopClock
Call ProtectAllWorksheets
ActiveWorkbook.Save
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal sh As Object, ByVal Target As Range)
Call StopClock
Call StartClock
End Sub
in Module
VBA Code:
Public NoActivity As Date
Sub StopClock()
On Error Resume Next
Application.OnTime NoActivity, "ShutDown", , False
End Sub
Sub StartClock()
NoActivity = now + TimeValue("00:05:00")
Application.OnTime NoActivity, "ShutDown"
End Sub
Sub ShutDown()
Application.DisplayAlerts = False
With ThisWorkbook
.Save
.Close
End With
End Sub