为什么这个Outlook 2007 VBA不起作用(我试图以编程方式删除标志)?

时间:2009-11-14 15:31:43

标签: vba outlook-2007 flags

我有一些代码可以为电子邮件添加标记,但是当我尝试使用下面的代码将其删除时,它似乎在Outlook 2007中没有任何效果。

    Public Sub Clear()
        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 = ""
                m.FlagStatus = olNoFlag
                m.FlagIcon = 0
                m.Save
            Next x

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

    End Sub

1 个答案:

答案 0 :(得分:3)

Outlook 2007不再支持2003风格的标志(它将它们映射到任务标志和最合适的类别颜色)。

您要清除的标志可能是任务标志。在那种情况下,执行

m.ClearTaskFlag
m.Save

将完成这项工作。