Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Application.ontime is running even after Excel workbook is closed

Posted on 2012-04-04
4
Medium Priority
?
440 Views
Last Modified: 2012-04-04
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.
0
Comment
Question by:vsuripeddi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 1200 total points
ID: 37807752
You have to kill the timer before you close the workbook. Store the start time in a variable and then use OnTime to kill it:

   On Error Resume Next
   Application.OnTime mTimerTime , "Autoclose", Schedule:=False
   On Error GoTo 0

Kevin
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 37807758
Place the above code in the Workbook_BeforeClose event handler.

Kevin
0
 

Author Comment

by:vsuripeddi
ID: 37807829
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?
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 37807838
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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a serious pitfall that can happen when deleting shapes using VBA.
Microsoft has changed the look and feel of Azure AD and Microsoft account sign-in pages so that you will have a more unified look and feel when moving between the two interfaces.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question