WaterSprite
Technical User
This Windows API timer code from Chip Pearson's site works really well for me. I have two spreadsheets that need to run once each hour. I put the code in one sheet, the "parent", so to speak. So I am controlling run times for the "parent" spreadsheet and another spreadsheet using Macro's in the timerproc block of code in the parent.
Now to my question. I need to run another spreadsheet, on the same computer but this one needs to run every 15 minutes. I think that with the delclarations being public, or global, I cannot just add another spreadsheet with the timer code set at 900 seconds, seems as if the 3600 second timerproc and the 900 second timerproc would not get along. I would assume I need to change the names, such as timerproc1, etc. But, I do not know what all to change to a different name, especially if I have to change names in the Public declarations portion.
The code below is as I am currently using it, 3600 in the timer seconds and two macros being ran from the timerproc block of code.
Thanks for your help.
'
Public Declare Function SetTimer Lib "user32" ( _
ByVal HWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" ( _
ByVal HWnd As Long, ByVal nIDEvent As Long) As Long
Public TimerID As Long
Public TimerSeconds As Single
Sub StartTimer()
TimerSeconds = 3600 ' how often to "pop" the timer.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
End Sub
Sub EndTimer()
On Error Resume Next
KillTimer 0&, TimerID
End Sub
Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, _
ByVal nIDEvent As Long, ByVal dwTimer As Long)
'
' The procedure is called by Windows. Put your
' timer-related code here.
' macro10
' macro11
'
End Sub
Now to my question. I need to run another spreadsheet, on the same computer but this one needs to run every 15 minutes. I think that with the delclarations being public, or global, I cannot just add another spreadsheet with the timer code set at 900 seconds, seems as if the 3600 second timerproc and the 900 second timerproc would not get along. I would assume I need to change the names, such as timerproc1, etc. But, I do not know what all to change to a different name, especially if I have to change names in the Public declarations portion.
The code below is as I am currently using it, 3600 in the timer seconds and two macros being ran from the timerproc block of code.
Thanks for your help.
'
Public Declare Function SetTimer Lib "user32" ( _
ByVal HWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" ( _
ByVal HWnd As Long, ByVal nIDEvent As Long) As Long
Public TimerID As Long
Public TimerSeconds As Single
Sub StartTimer()
TimerSeconds = 3600 ' how often to "pop" the timer.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
End Sub
Sub EndTimer()
On Error Resume Next
KillTimer 0&, TimerID
End Sub
Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, _
ByVal nIDEvent As Long, ByVal dwTimer As Long)
'
' The procedure is called by Windows. Put your
' timer-related code here.
' macro10
' macro11
'
End Sub