Pause Outlook for a specified time

I am trying to run Outlook code 10 seconds after receiving a message.

I tried to use application.wait

, but you can't seem to do it with Outlook.

How to pause Outlook for a specific amount of time?

+3


source to share


2 answers


You can create a Sub that will simulate Application.Wait

something like.

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'For 64-Bit
'Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Sub Pause(intSeconds As Variant)
  ' Comments: Waits for a specified number of seconds
  ' Params  : intSeconds      Number of seconds to wait
  ' Source  : Total Visual SourceBook

On Error GoTo PROC_ERR

    Dim datTime As Date
    datTime = DateAdd("s", intSeconds, Now)
    Do
        ' Yield to other programs (better than using DoEvents which eats up all the CPU cycles)
        Sleep 100
        DoEvents
    Loop Until Now >= datTime
PROC_EXIT:
    Exit Sub

PROC_ERR:
    MsgBox "Error: " & Err.Number & ". " & Err.Description, , "Pause Method"
    Resume PROC_EXIT
End Sub

      



To trigger this, you can use Pause 3

+4


source


Here's a simple way:



    T0 = Now + TimeValue("0:00:10")
    Do Until Now > T0
    Loop

      

0


source







All Articles