Search code examples
vbams-wordlatency

delayed run of vba macros in microsoft word


How to intermittently run two macros in a module (two subprocesses) and we have a latency (wait time for example 700 seconds) to request user to change the position of cursor to the desirable location and then second macro will be run based on new position of cursor


Solution

  • Sub Main()
        'Here you execute or run the 1st macro
        call Macro1
    
        'Now we inform the user with a messagebox
        'for the next action they have to take
        'and the time limit within which to complete the action
        'after closing the msgbox
        msgbox "You have 10 seconds after you close this to move your mouse."
        dim WaitUntil
        WaitUntil=Now+timeserial(0,0,10)
        'Wait a certain amount of time
        do while now<=WaitUntil
        doevent
        loop
        
        'Now user must have completed the manual action
        'so we can proceed with the second Macro
        call Macro2
    End Sub
    
    Sub Macro1()
        'code
    End Sub
    
    Sub Macro2()
        'code
    End Sub