Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
StatusBar
Application.StatusBar = "GCF" ' TEST Use GCF fo
test

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
StatusBar
Application.DisplayStatusBar = False ' Turn of
StatusBar Display

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

On Error GoTo 0 ' Turn off erro
trapping.
On Error Resume Next ' Defer erro
trapping.
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

--
GC
-----------------------------------------------------------------------
GCF's Profile: http://www.excelforum.com/member.php...nfo&userid=412
View this thread: http://www.excelforum.com/showthread.php?threadid=26236

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default OnTime problem.

No, it will only cancel the specific Ontime event scheduled for the time
provided. You should not have more than one ontime event pending - have the
ontime event schedule the next one. This is demonstrated by Chip Pearson:

http://www.cpearson.com/excel/ontime.htm

--
Regards,
Tom Ogilvy

"GCF" wrote in message
...

Please help me. I am making an attempt to learn VBA via the cut and
paste / trial and error methods. Enclosed is some code I put together
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 my
understanding that executing OnTime with Schedule equal to False will
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 on
StatusBar
Application.StatusBar = "GCF" ' TEST Use GCF for
test

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 SaveFile
to exec again

End Sub
Sub Auto_Close()

Application.DisplayAlerts = True
Application.ScreenUpdating = True

Application.DisplayStatusBar = oldStatusBar ' Restore to orig
StatusBar
Application.DisplayStatusBar = False ' Turn off
StatusBar Display

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

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

End Sub

Sub Terminator() ' Stub for
Auto_Close OnTime
End Sub


--
GCF
------------------------------------------------------------------------
GCF's Profile:

http://www.excelforum.com/member.php...fo&userid=4124
View this thread: http://www.excelforum.com/showthread...hreadid=262367



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find %ontime & SUMIF ontime ie: find matching sets within Range... Chris T-M Excel Worksheet Functions 3 October 10th 08 08:14 PM
.ontime Grrrrrumpy Excel Discussion (Misc queries) 2 April 8th 07 04:18 PM
OnTime...Please Help Michael_I Excel Programming 9 May 24th 04 07:56 PM
OnTime Problem Peter Pantus Excel Programming 7 October 19th 03 03:34 PM
OnTime problem Peter Pantus Excel Programming 1 October 19th 03 02:41 AM


All times are GMT +1. The time now is 07:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"