I have an excel 2007 workbook. I need to automatically close it after 5 minutes of opening it. I had written a code as under and this works
Private Sub Workbook_Open()
Application.OnTime Now() + TimeValue("00:05:00"), "Autoclose"
End Sub
Sub Autoclose()
ThisWorkbook.Save
ThisWorkbook.Close
End Sub
However, in case I close this Excel workbook after 2 minutes of opening it, the Excel application is still opening the closed workbook and then again closing it.
This should not happen. The excel application should close only if the Excel application is manually opened by me. Please suggest a method / VBA code.
Private Sub Workbook_Open()
Application.OnTime Now() + TimeValue("00:05:00"), "Autoclose"
End Sub
Sub Autoclose()
ThisWorkbook.Save
ThisWorkbook.Close
End Sub
However, in case I close this Excel workbook after 2 minutes of opening it, the Excel application is still opening the closed workbook and then again closing it.
This should not happen. The excel application should close only if the Excel application is manually opened by me. Please suggest a method / VBA code.