ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   2 Timers (https://www.excelbanter.com/excel-programming/327382-re-2-timers.html)

Harald Staff

2 Timers
 
Hi Al

I'd put a "what time is is ?" check into the 30 sec loop and have that one
call the once-an-hour-procedure at the right time. But you provide too
little detail to make me say "That's the very best solution" ;-)

HTH. Best wishes Harald


"Al" skrev i melding
...
I have code that runs every 30 second to update a file. I have another

macro
that I need to run at 15 minutes after the hour to update another file.

What
is the best approach to accomplish this?
Thanks for the help!
Al




Harald Staff

2 Timers
 

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat,
schedule:=True
If Minute(Time) = 15 Then
If Second(Time) <= 30 Then UpdateOtherFile
End If
End Sub

HTH. Best wishes Harald

"Al" skrev i melding
...
OK Here is the 30 second code.....

Public RunWhen As Double
Public Const cRunIntervalSeconds = 30
Public Const cRunWhat = "Macro2"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat,

schedule:=True
End Sub


Sub Stop_Timer()
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat,

schedule:=False

End Sub


Sub Macro2()
Application.ScreenUpdating = False

On Error Resume Next
Kill "G:\Operations Planning\PowerWorld\mwdata.xls"
On Error GoTo 0
Workbooks.OpenText Filename:="G:\MyPath\Myfile.txt _
Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False,

_
Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1)), TrailingMinusNumbers:=True
ActiveWorkbook.SaveAs Filename:= _
"G:\mypath\myfile.xls", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
ActiveWorkbook.Close SaveChanges:=False
' added line to schedule the next run
StartTimer
Application.ScreenUpdating = True
End Sub

Then every hour at 15 after my sub UpdateOtherFile() would run




"Harald Staff" wrote:

Hi Al

I'd put a "what time is is ?" check into the 30 sec loop and have that

one
call the once-an-hour-procedure at the right time. But you provide too
little detail to make me say "That's the very best solution" ;-)

HTH. Best wishes Harald


"Al" skrev i melding
...
I have code that runs every 30 second to update a file. I have

another
macro
that I need to run at 15 minutes after the hour to update another

file.
What
is the best approach to accomplish this?
Thanks for the help!
Al








All times are GMT +1. The time now is 03:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com