vsuripeddi
asked on
Application.ontime is running even after Excel workbook is closed
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What should be the value of mTimerTime? Can I still use
mTimerTime = Application.OnTime Now() + TimeValue("00:05:00") ?
Or should mTimerTime be of a different value?
mTimerTime = Application.OnTime Now() + TimeValue("00:05:00") ?
Or should mTimerTime be of a different value?
You want to set mTimerTime to whatever time you want the timer to pop. Then use that same value to kill the timer should you close the workbook before the timer can pop.
Kevin
Kevin
Kevin