Pause Outlook for a given amount of time

断了今生、忘了曾经 提交于 2019-12-23 12:42:57

问题


I'm trying to run Outlook code 10 seconds after an email is received.

I tried using application.wait but it appears that you cannot do this with Outlook.

How do I pause Outlook for a given amount of time?


回答1:


You can create a Sub that will mimic the 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 call this you could use Pause 3




回答2:


Here's a simple way:

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


来源:https://stackoverflow.com/questions/30196269/pause-outlook-for-a-given-amount-of-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!