暂停Outlook一段时间

时间:2015-05-12 16:12:02

标签: vba outlook outlook-vba

我收到电子邮件后10秒钟尝试运行Outlook代码。

我尝试使用application.wait但似乎无法使用Outlook执行此操作。

如何在给定时间内暂停Outlook?

3 个答案:

答案 0 :(得分:5)

您可以创建一个模仿Application.Wait的Sub,类似于。

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

要拨打此电话,您可以使用Pause 3

答案 1 :(得分:0)

这是一个简单的方法:

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

答案 2 :(得分:0)

在其中抛出DoEvents可以了

T0 = Now + TimeValue("00:00:10")

Do Until Now > 10

  DoEvents

Loop