How to use Application.OnTime to call a macro at a set time everyday, without having to close workbook

前端 未结 1 1117
[愿得一人]
[愿得一人] 2020-12-11 07:57

I have written a macro that uses Application.OnTime that works if I manually execute the macro. I\'m trying to automate this process so I don\'t have to write Application.On

相关标签:
1条回答
  • 2020-12-11 08:46

    You could create a kind of recurrence procedure. It could look as follows:

    Sub Call_At_3_30()
        'first call appropriate procedure 
        Call myProcedure
        'next, set new calling time
        Application.OnTime TimeValue("3:30:00"), "Call_At_3_30"
    End Sub
    

    Somewhere you will keep your main procedure, it this situation:

    Sub myProcedure
        'your code here
    End Sub
    

    In this situation you need to run first subroutine Call_At_3_30 only once. But you need to remember that Excel must be turned on all the time.

    Optionally, if you want to call your procedure after 24 hours you could change .OnTime instruction in this way:

    Application.OnTime Now + 1, "Call_At_3_30"
    

    Some other modifications are possible, too.

    0 讨论(0)
提交回复
热议问题