7

我在 Outlook 2010 中有一个简单的 VBA 代码,它会自动打印任何传入的电子邮件。

此脚本设置为在每次通过规则收到电子邮件时运行。

这是代码:

Sub printradu(Item As Outlook.MailItem)
       MessageAndAttachmentProcessor Item, True
End Sub

我怎样才能让这个脚本等待 10 秒然后执行它。我需要这样的东西:

Sub printradu(Item As Outlook.MailItem)
       'Wait 10 seconds then execute the code below:
       MessageAndAttachmentProcessor Item, True
End Sub
4

2 回答 2

13

尝试:

Sub printradu(Item As Outlook.MailItem)
    'Wait 10 seconds then execute the code below:
    Application.Wait(Now + TimeValue("0:00:10"))
    MessageAndAttachmentProcessor Item, True
End Sub

或者:

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub printradu(Item As Outlook.MailItem)
    'Wait 10 seconds then execute the code below:
    Sleep(10000)
    MessageAndAttachmentProcessor Item, True
End Sub

或者:

Sub printradu(Item As Outlook.MailItem)
    'Wait 10 seconds then execute the code below:
    Threading.thread.sleep(10000)
    MessageAndAttachmentProcessor Item, True
End Sub
于 2013-10-05T10:02:14.877 回答
3

这在 Outlook 2013 VBA 中对我有用(由于某种原因,我必须在“Application.Wait”之前包含“outlook。”):

Outlook.Application.Wait (Now + TimeValue("0:00:5"))
于 2018-11-07T11:00:31.677 回答