vba Outlook 等待几秒钟然后执行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19196391/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:49:05  来源:igfitidea点击:

Outlook Wait a few seconds then execute

vbaoutlook-vba

提问by RaduS

I have a simple VBA code in Outlook 2010 which prints any incoming emails automatically.

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

This script is set to run each time an email comes in through a rule.

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

Here is the code:

这是代码:

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

How can i make this script wait 10 seconds and then execute it. I need something like this:

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

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

回答by Vivek Jain

Try:

尝试:

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

Or:

或者:

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

Or:

或者:

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

回答by Sérgio Backes

This worked for me in Outlook 2013 VBA (for some reason I had to include "outlook." before the "Application.Wait"):

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

Outlook.Application.Wait (Now + TimeValue("0:00:5"))