Home > Back-end >  Call Macros needs some changes in it
Call Macros needs some changes in it

Time:11-22

I am calling some macros via VBA cod i need some changes in it, i will be thankful if any help could be provided

Sub Button1_Click()

    Call moveFilesFromListPartial
    Call moveFilesFromListPartial_AA
    Call moveAllFilesInDateFolderIfNotExist
    Application.OnTime Now   TimeValue("00:01:00"), "Button1_Click"
End Sub

In this current VBA macro all the macros run after one minutes however i request if 3rd macro which is moveAllFilesInDateFolderIfNotExist should run after 5 seconds of first 2 macros. i.e. first 2 macros should be run after 60 seconds and third macro should be run after 65 seconds. this should be the loop every time

i will be grateful

CodePudding user response:

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

CodePudding user response:

Like this maybe:

Sub Button1_Click()
    Call 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
  •  Tags:  
  • vba
  • Related