PDA

View Full Version : Looping timer



abesimpson
04-16-2008, 04:21 PM
I am running the following (3) code to run a macro ( ExportOnTime) every 10 minutes.
Sub Start()

Loop_Time

End Sub
-----------------------------------------

Public dTime As Date

Sub Loop_Time() '<<Set frequency of Account XML export

dTime = Now + TimeValue("00:10:00")

Application.OnTime dTime, "Loop_Time"

Application.ScreenUpdating = False

ExportOnTime '<<Account export timer

End Sub
------------------------------------
Private Sub Workbook_BeforeClose(cancel As Boolean)

Application.OnTime dTime, "XML_Time", , False

End Sub
If I try to exit the spreadsheet using the small x I get an error message on "Application.OnTime dTime, "XML_Time", , False". As I never stop the macro before I exit the spreadsheet I am wondering if eliminating this
item will cause me some unintended probelm in the long-run?

Bob Phillips
04-16-2008, 06:15 PM
Surely it should be



Private Sub Workbook_BeforeClose(cancel As Boolean)

Application.OnTime dTime, "Loop_Time", , False

End Sub

abesimpson
04-16-2008, 06:47 PM
Doh!, (but same results).

Made the chage to the proper sub name, but still get an error when I try to exit via the small x.

So my question remains, if I the loop macro always runs when the spreadsheet is open, do I need this if I am closing the spreadsheet.


Great catch!



abe

Bob Phillips
04-16-2008, 07:02 PM
You do, else it will re-open the book.

Where is dTime and Loop_time defined?

abesimpson
04-16-2008, 07:28 PM
They are defined in the same module.

I have tried commenting out "Application.OnTime dTime, "Loop_Time", , False".

Loop_Time runs properly and the when I exit the spreadsheet does not reopen.

Now I'm really confused.