暂停 Outlook 一段时间
Pause Outlook for a given amount of time
我正尝试在收到电子邮件 10 秒后 运行 Outlook 代码。
我尝试使用 application.wait
,但您似乎无法使用 Outlook 执行此操作。
如何暂停 Outlook 一段时间?
您可以创建一个模仿 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
这里有一个简单的方法:
T0 = Now + TimeValue("0:00:10")
Do Until Now > T0
Loop
在这丢个DoEvents就可以了
T0 = Now + TimeValue("00:00:10")
Do Until Now > 10
DoEvents
Loop
我不确定是否需要复杂的功能..
试试这个:
#If VBA7 Then
'Code is running VBA7 (2010 or later).
#If Win64 Then
'Code is running in 64-bit version of Microsoft Office.
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#Else
'Code is running in 32-bit version of Microsoft Office.
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
#Else
'Code is running VBA6 (2007 or earlier).
#End If
Sub Test()
Debug.Print Now
Sleep 10000
Debug.Print Now
End Sub
我正尝试在收到电子邮件 10 秒后 运行 Outlook 代码。
我尝试使用 application.wait
,但您似乎无法使用 Outlook 执行此操作。
如何暂停 Outlook 一段时间?
您可以创建一个模仿 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
这里有一个简单的方法:
T0 = Now + TimeValue("0:00:10")
Do Until Now > T0
Loop
在这丢个DoEvents就可以了
T0 = Now + TimeValue("00:00:10")
Do Until Now > 10
DoEvents
Loop
我不确定是否需要复杂的功能..
试试这个:
#If VBA7 Then
'Code is running VBA7 (2010 or later).
#If Win64 Then
'Code is running in 64-bit version of Microsoft Office.
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#Else
'Code is running in 32-bit version of Microsoft Office.
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
#Else
'Code is running VBA6 (2007 or earlier).
#End If
Sub Test()
Debug.Print Now
Sleep 10000
Debug.Print Now
End Sub