Reputation: 239
I am calling macros via VBA code.
Sub Button1_Click()
Call moveFilesFromListPartial
Call moveFilesFromListPartial_AA
Call moveAllFilesInDateFolderIfNotExist
Application.OnTime Now + TimeValue("00:01:00"), "Button1_Click"
End Sub
All the macros run after one minute.
I want the third macro moveAllFilesInDateFolderIfNotExist
to run after 5 seconds of first two macros. i.e. first two macros should be run after 60 seconds and third macro should be run after 65 seconds. This should be the loop every time.
Upvotes: 0
Views: 104
Reputation: 166685
Like this maybe:
Sub Button1_Click()
Application.OnTime Now + TimeValue("00:01:00"), "Part1"
End Sub
Sub Part1()
Call moveFilesFromListPartial
Call moveFilesFromListPartial_AA
'wait 5sec before running the next part
Application.OnTime Now + TimeValue("00:00:05"), "Part2"
End Sub
Sub Part2()
Call moveAllFilesInDateFolderIfNotExist
Application.OnTime Now + TimeValue("00:01:00"), "Part1"
End Sub
Upvotes: 0
Reputation: 265
if my understanding is correct, you want to execute macro #3 5 seconds after the 2 first ones where executed.
I suggest to use the Application.Wait
method to help you do this:
Sub Button1_Click()
Call moveFilesFromListPartial
Call moveFilesFromListPartial_AA
Application.Wait(Now + TimeValue("00:00:05")) ' 5 seconds to wait
Call moveAllFilesInDateFolderIfNotExist
Application.OnTime Now + TimeValue("00:01:00"), "Button1_Click"
End Sub
You could also import the Sleep
method by writing
Public Declare Sub Sleep Lib "kernel32" (ByVal dwmilliseconds As Long)
at the beginning of you module, then calling Sleep 5000
before calling moveAllFilesInDateFolderIfNotExist
Hope this helps
Upvotes: 1