OnTime problem.



Please help me. I am making an attempt to learn VBA via the cut an
paste / trial and error methods. Enclosed is some code I put togethe
that seems to work fine until I close the file and within 15 seconds
the closed file is resurrected in the “SaveFile” procedure. It is m
understanding that executing OnTime with Schedule equal to False wil
override and cancel any pending OnTime process. What am I doing wrong

Sub Auto_Open()

Application.StatusBar = False ' Clear previous

oldStatusBar = Application.DisplayStatusBar ' Save existing
Application.DisplayStatusBar = True ' Turn o
Application.StatusBar = "GCF" ' TEST Use GCF fo

MsgBox ("Start " & Now & " " & MyTime) ' TEST

Call SaveFile

End Sub

Sub SaveFile()

' ActiveWorkbook.Save ' Save File
MsgBox ("SaveFile " & Now & " " & MyTime) ' Test

Application.OnTime Now + TimeValue("00:00:15"), _
"SaveFile" ' Re-run every TmeValue ' Schedule SaveFil
to exec again

End Sub
Sub Auto_Close()

Application.DisplayAlerts = True
Application.ScreenUpdating = True

Application.DisplayStatusBar = oldStatusBar ' Restore to ori
Application.DisplayStatusBar = False ' Turn of
StatusBar Display

MsgBox ("Auto_Close " & Now & " " & MyTime) ' Test

On Error GoTo 0 ' Turn off erro
On Error Resume Next ' Defer erro
Application.OnTime Now + TimeValue("00:00:02"), _
"Terminator", , False ' Overrid
Application.OnTime in play

End Sub

Sub Terminator() ' Stub fo
Auto_Close OnTime
End Su

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question