Outlook Wait a few seconds then execute

杀马特。学长 韩版系。学妹 提交于 2019-12-22 05:00:31

问题


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

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:

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

回答1:


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



回答2:


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

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


来源:https://stackoverflow.com/questions/19196391/outlook-wait-a-few-seconds-then-execute

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