PDA

View Full Version : Advice on 'OnTime'



paulked
04-08-2020, 01:21 AM
Hi all

I have an application that reads data from a webpage which is updated at 03:45 daily. Occasional updates to the webpage are also carried out at other times, I am notified of these by email.

I have written this code which should update every morning at 4am and, after hitting a button, when I am emailed notification of an update:



Option Explicit


Global AutoRun As Boolean


Sub AutoUpdate()
Application.OnTime ("04:00:00"), "UpdateData"
End Sub


Sub ManualUpdate() 'run by a command button
AutoRun = False
UpdateData
End Sub


Sub UpdateData()
'Code to update here...
If AutoRun Then AutoUpdate
AutoRun = True
End Sub


I seldom use OnTime so I am seeking advice as to whether this is okay to go with, or if there is a better way to approach this.

Any pointers would be most welcome :bow:

Thanks in advance

snb
04-08-2020, 01:34 AM
see

https://www.snb-vba.eu/VBA_Application.OnTime_en.html

paulked
04-08-2020, 07:09 AM
That's the first place I went to, you are my 'goto' site for a vba handbook :thumb

My doubts lie in its' simplicity... can it be reliable?

snb
04-08-2020, 08:33 AM
dim y

Sub AutoUpdate()
M_snb
y=1+ date + 1/6
Application.OnTime y, "AutoUpdate"
End Sub

Sub ManualUpdate() 'run by a command button
M_snb
End Sub

sub M_snb()
' code to update
end sub

paulked
04-08-2020, 09:09 AM
Thanks. That looks better, I'll give it a whirl :thumb