How to force a workbook to close after inactivity in Excel
In Excel, you can force a workbook to close after a period of inactivity by using the Workbook Close event. This event occurs when the workbook is closed, either through the File menu or by clicking the Close button on the workbook window. You can use this event to check for inactive periods and then close the workbook if desired.
To use the Workbook Close event:
Open the workbook in which you want to check for inactivity.
Press Alt+F11 to open the Visual Basic Editor.
In the Project Explorer window, double-click ThisWorkbook.
In the Code window, click Workbook in the Object drop-down list at the top of the window.
Click Workbook_Close in the Procedure drop-down list.
Enter your code in the Code window.
Private Sub Workbook_Close()
'Check for inactivity
If Application.ActiveWorkbook Is Nothing Then
'No activity for 5 minutes
If Now - ThisWorkbook.SavedTime > TimeValue("00:05:00") Then
'Save changes and close workbook
Get started with Causal today. Build models effortlessly, connect them directly to your data, and share them with interactive dashboards and beautiful visuals.