Hi All,
I've set up two macro's in my workbook to run at given times (when first opened, and then 15 min and 30 min respectively).
They run fine on open, but then they both seem to decide to run when ever they feel like it after the first occurrence, most often at sooner time intervals than specified eg. every 3 min or something.
This is the workbook open code:
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.OnTime dTime1, "ImportData", , False
Application.OnTime dTime2, "Linear", , False
End Sub
Private Sub Workbook_Open()
dTime1 = Now + TimeValue("00:15:00")
Application.OnTime dTime1, "ImportData"
dTime2 = Now + TimeValue("00:30:00")
Application.OnTime dTime2, "Linear"
End Sub
And the start of both the other macro's;
Public dTime2 As Date
Sub Linear()
dTime2 = Now + TimeValue("00:30:00")
Application.OnTime dTime2, "Linear"
Application.ScreenUpdating = False
'MY MACRO HERE
Next example:
Public dTime1 As Date
Sub ImportData()
dTime1 = Now + TimeValue("00:15:00")
Application.OnTime dTime1, "ImportData"
' ImportData Macro
' Macro recorded by Me
On Error GoTo ErrorHandler
'MY MACRO HERE
The only thing i can think of (but im sure i'll have other errors pointed out) is that because i have web queries and Microsoft WebBrowser embedded content, it may be tripping the OpenWorkbook??? But that should make it loop continuously wouldn't it?
Also i have Application.Wait Now + TimeValue("00:00:05") entries in my macro, to make it pause before continuing, don't know if this effects it.
I've set up two macro's in my workbook to run at given times (when first opened, and then 15 min and 30 min respectively).
They run fine on open, but then they both seem to decide to run when ever they feel like it after the first occurrence, most often at sooner time intervals than specified eg. every 3 min or something.
This is the workbook open code:
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.OnTime dTime1, "ImportData", , False
Application.OnTime dTime2, "Linear", , False
End Sub
Private Sub Workbook_Open()
dTime1 = Now + TimeValue("00:15:00")
Application.OnTime dTime1, "ImportData"
dTime2 = Now + TimeValue("00:30:00")
Application.OnTime dTime2, "Linear"
End Sub
And the start of both the other macro's;
Public dTime2 As Date
Sub Linear()
dTime2 = Now + TimeValue("00:30:00")
Application.OnTime dTime2, "Linear"
Application.ScreenUpdating = False
'MY MACRO HERE
Next example:
Public dTime1 As Date
Sub ImportData()
dTime1 = Now + TimeValue("00:15:00")
Application.OnTime dTime1, "ImportData"
' ImportData Macro
' Macro recorded by Me
On Error GoTo ErrorHandler
'MY MACRO HERE
The only thing i can think of (but im sure i'll have other errors pointed out) is that because i have web queries and Microsoft WebBrowser embedded content, it may be tripping the OpenWorkbook??? But that should make it loop continuously wouldn't it?
Also i have Application.Wait Now + TimeValue("00:00:05") entries in my macro, to make it pause before continuing, don't know if this effects it.