Outlook VBA 用于在发送前将新邮件标记为任务 [英] Outlook VBA for marking a new mail as a task before sending

查看:79
本文介绍了Outlook VBA 用于在发送前将新邮件标记为任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经试过了:

Sub SendAwaitingResponse()
  Dim mail As MailItem
  Set mail = Outlook.Application.ActiveInspector.CurrentItem
  mail.MarkAsTask (olMarkToday)
  mail.Categories = "Awaiting Response"
  mail.Send
End Sub

出现以下错误:

无法标记草稿项.MarkAsTask 仅对已发送或已接收的项目有效.

Draft Items cannot be marked. MarkAsTask is only valid on items that have been sent or received.

可以在UI中点击跟进",邮件发送后会被标记为任务.我认为没有办法以编程方式做到这一点.

It is possible to click "Follow up" in the UI, and then the mail will be marked as task after sent. I see no way to do it programmatically.

推荐答案

创建与发送等待响应"按钮关联的宏,以便使用自定义属性标记已发送的电子邮件:

Create a macro associated to a button "Send Awaiting Response", in order to mark sent emails with a custom property:

Sub SendAwaitingResponse()
    Dim Mail As MailItem
    Set Mail = Outlook.Application.ActiveInspector.CurrentItem
    Dim Property As UserProperty
    Set Property = Mail.UserProperties.Add("FlagAwaitingResponse", olYesNo)
    Property.Value = True
    Mail.Send
End Sub

在 ThisOutlookSession 对象中,订阅添加到已发送邮件"文件夹中的项目.使用自定义属性标记的项目将被标记为 Outlook 任务.

Inside the ThisOutlookSession object, subscribe to items added to the Sent Items folder. Items marked with the custom property will be marked as an Outlook task.

Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
    Dim SentItems As Folder
    Set SentItems = Outlook.Application.GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail)
    Set Items = SentItems.Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
    Dim Mail As MailItem
    Set Mail = Item

    Set Property = Mail.UserProperties("FlagAwaitingResponse")
    If Property Is Nothing Then Exit Sub

    Mail.Categories = "Awaiting Response"
    Mail.MarkAsTask (olMarkToday)
    Mail.Save
End Sub

不要忘记启用 Outlook 宏以使其正常工作.

Don't forget to enable Outlook macros for this to work.

这篇关于Outlook VBA 用于在发送前将新邮件标记为任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆