0

I want my code to run on 10 minute intervals throughout the work day, but stop when the work day is over. Currently my code uses

Application.OnTime Now + TimeValue("00:10:00"), "!Module1.Refresh3"

but it causes problems as it continues to run all night.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
kcourt
  • 3
  • 1
  • [This](https://www.ozgrid.com/forum/forum/help-forums/excel-general/124093-application-ontime-run-function-every-10-minutes-between-7-00-00am-and-7-00-00pm) could be helpfull – JvdV Feb 01 '19 at 13:53
  • 1
    What is the job you want to perform? Would a tool like the unix cron not be more suitable to a task which has to be performed throughout the day? see **What is the Windows version of cron?** https://stackoverflow.com/questions/132971/what-is-the-windows-version-of-cron – simple-solution Feb 01 '19 at 14:06
  • You need to give a bit more clarification: do you consider a bank holiday a work day? (I suspect not). If not, then you need some more logic than just having it run during working day – Zac Feb 01 '19 at 14:32

1 Answers1

0

You could do something along the lines of:

If Hour(Now) > 19 Then
    Application.Wait (Now + TimeValue("12:00:00"))
End If

This would stop your code from 8pm onwards for 12 hours. For clearification: As peakpeak mentioned, make sure you run this in your outer loop, so after every 10 minute interval these lines get evaluated.

seulberg1
  • 955
  • 1
  • 7
  • 19
  • The code should be in an outer loop, otherwise it'll only execute once at best –  Feb 01 '19 at 14:38