(OUTLOOK上的VBA)检查是否未收到电子邮件vba

时间:2015-04-03 13:59:37

标签: email outlook-vba

我在Outlook上需要一个宏来执行以下逻辑:

  • 从上午9:00到上午10:00之间的每个工作日,如果有任何电子邮件,请检查特定文件夹。
  • 如果没有电子邮件,请发送简单邮件给特定的人。

非常感谢。

1 个答案:

答案 0 :(得分:0)

  

从上午9:00到上午10:00之间的每个工作日,如果有任何电子邮件,请检查特定文件夹。

您需要运行计时器以定期运行任务。有关详细信息,请参阅Outlook VBA - Run a code every half an hour。使用Items类的Find / FindNext或Restrict方法查找与您的条件对应的Outlook项目。

  

如果没有电子邮件,请发送简单邮件给特定的人。

如果找不到项目,请参阅#1,您可以创建并提交邮件项目。

      ' Create the message.
      Set objOutlookMsg  = objOutlook.CreateItem(olMailItem)

      With objOutlookMsg
          ' Add the To recipient(s) to the message.
          Set objOutlookRecip = .Recipients.Add("Nancy Davolio")
          objOutlookRecip.Type = olTo

          ' Add the CC recipient(s) to the message.
          Set objOutlookRecip = .Recipients.Add("Michael Suyama")
          objOutlookRecip.Type = olCC

         ' Add the BCC recipient(s) to the message.
          Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
          objOutlookRecip.Type = olBCC

         ' Set the Subject, Body, and Importance of the message.
         .Subject = "This is an Automation test with Microsoft Outlook"
         .Body = "This is the body of the message." &vbCrLf & vbCrLf
         .Importance = olImportanceHigh  'High importance

         ' Resolve each Recipient's name.
         For Each ObjOutlookRecip In .Recipients
             objOutlookRecip.Resolve
         Next

        .Save
        .Send
      End With
相关问题