Good Afternoon,
I am having an issues with a particular code:
In the ThisWorkbook module:
Option Explicit
Private Sub Workbook_Open()
LastActivityTime = Now()
Check_Inactivity
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
LastActivityTime = Now()
End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
LastActivityTime = Now()
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
LastActivityTime = Now()
End Sub
And, in a standard moduleOption Explicit
Public LastActivityTime As Date
Sub Check_Inactivity()
Const Inactivity_Delay As Date = #12:05:00 AM#
If LastActivityTime + Inactivity_Delay < Now() Then
ThisWorkbook.Close True
Else
Application.OnTime LastActivityTime + Inactivity_Delay, "Check_Inactivity"
End If
End Sub
The code works perfectly to what I would like it to do, but often times it completely breaks my ability to open the spreadsheet at all.
It will get to 100%, then crash, or just not even show the excel window at all. It causes other sheets to crash.
Does anyone else have a better code that runs more efficiently?
Ideally it would save and close after 5 mins of inactivity.
Thank you!
I am having an issues with a particular code:
In the ThisWorkbook module:
Option Explicit
Private Sub Workbook_Open()
LastActivityTime = Now()
Check_Inactivity
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
LastActivityTime = Now()
End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
LastActivityTime = Now()
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
LastActivityTime = Now()
End Sub
And, in a standard moduleOption Explicit
Public LastActivityTime As Date
Sub Check_Inactivity()
Const Inactivity_Delay As Date = #12:05:00 AM#
If LastActivityTime + Inactivity_Delay < Now() Then
ThisWorkbook.Close True
Else
Application.OnTime LastActivityTime + Inactivity_Delay, "Check_Inactivity"
End If
End Sub
The code works perfectly to what I would like it to do, but often times it completely breaks my ability to open the spreadsheet at all.
It will get to 100%, then crash, or just not even show the excel window at all. It causes other sheets to crash.
Does anyone else have a better code that runs more efficiently?
Ideally it would save and close after 5 mins of inactivity.
Thank you!