有没有办法在 VBA 中添加特定类别并标记电子邮件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1734395/
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-11 11:00:11  来源:igfitidea点击:

Is there any way to add a specific category and flag an email in VBA?

vbaoutlook-2007

提问by leora

I normally go through my email and flag anything for follow up and categorize for:

我通常会浏览我的电子邮件并标记任何内容以进行跟进和分类:

  1. Phone Call
  2. Email
  3. Talk To
  4. Setup meeting
  1. 电话
  2. 电子邮件
  3. 与人交谈
  4. 设置会议

Is there any way in a Outlook VBA macro, I can (in a single macro), both flag an item for follow and set one of the above categories on it?

在 Outlook VBA 宏中有什么方法吗,我可以(在单个宏中)标记一个项目以供关注并在其上设置上述类别之一?

回答by leora

I have found the answer . .listed below . . .

我找到了答案。。下面列出 。. .

Private Sub TagArchived1(category As String)

    Dim objOutlook As Outlook.Application
    Dim objInspector As Outlook.Inspector

    Dim strDateTime As String

    ' Instantiate an Outlook Application object.
    Set objOutlook = CreateObject("Outlook.Application")

    ' The ActiveInspector is the currently open item.
    Set objExplorer = objOutlook.ActiveExplorer

    ' Check and see if anything is open.
    If Not objExplorer Is Nothing Then
        ' Get the current item.
        Dim arySelection As Object
        Set arySelection = objExplorer.Selection

        For x = 1 To arySelection.Count
            Dim m As MailItem
            Set m = arySelection.Item(x)
            m.Categories = category
            m.FlagStatus = olFlagMarked
            m.FlagIcon = 6
            m.Save
        Next x

    Else
        ' Show error message with only the OK button.
        MsgBox "No explorer is open", vbOKOnly
    End If

    ' Set all objects equal to Nothing to destroy them and
    ' release the memory and resources they take.
    Set objOutlook = Nothing
    Set objExplorer = Nothing
End Sub