如何在 Outlook 2007 中僅保留給定主題的最新郵件?

如何在 Outlook 2007 中僅保留給定主題的最新郵件?

我們有一個透過電子郵件發送更新的自動化系統。很好,對我來說這是有用的信息。我寧願只看到最新的更新,而把其餘的都丟掉。也就是說,給定以下列表

在此輸入影像描述

我只希望 34022 更新的選定版本保留在我的資料夾中。我已經研究過規則,但似乎沒有什麼符合要求。

有沒有辦法(自動)刪除我不想要的?

答案1

帶有一些VBA。當涉及到刪除時,徹底測試總是一個好主意。

Private Sub Application_NewMail()
' In ThisOutlookSession module

' see Create Outlook Rules Programmatically
' http://msdn.microsoft.com/en-us/library/aa163981(v=office.10).aspx

Dim olApp As Outlook.Application
Dim olNs As Outlook.NameSpace
Dim olFld As Outlook.MAPIFolder
Dim objMail As Object

Set olApp = Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set olFld = olNs.GetDefaultFolder(olFolderInbox)

olFld.items.sort "Received", False
'Set objMail = olFld.items.GetFirst ' In Outlook 2003
Set objMail = olFld.items.GetLast ' In Outlook 2010

If TypeOf objMail Is MailItem Then

    If objMail.SenderEmailAddress = "Found in DetermineSenderEmailAddress" And _
        InStr(1, objMail.Subject, "Ticket:") Then

            DeleteOldStatus objMail

    End If

End If

Set objMail = Nothing
Set olFld = Nothing
Set olNs = Nothing
Set olApp = Nothing

End Sub

Sub DeleteOldStatus(objMail As MailItem)

Dim olFld As folder
Dim olNs As NameSpace
Dim olderMail As MailItem

Dim iDel As Long

Set olNs = Application.GetNamespace("MAPI")
Set olFld = olNs.GetDefaultFolder(olFolderInbox)

For iDel = olFld.items.Count To 1 Step -1

    Set olderMail = olFld.items(iDel)

    If olderMail.Subject = objMail.Subject Then

        If olderMail.ReceivedTime < objMail.ReceivedTime Then

            Debug.Print olderMail.Subject & " received  " & olderMail.ReceivedTime & " should be deleted."
            'olderMail.Delete ' Remove leading apostrophe to uncomment when ready

        End If

    End If

Next

Debug.Print "Done - " & objMail.Subject

End Sub


Sub DetermineSenderEmailAddress()

' open up an email then run

Dim currItem As MailItem
Set currItem = ActiveInspector.currentItem

' Copy the text from the immediate pane.
Debug.Print currItem.SenderEmailAddress

End Sub

編輯器和按鈕幫助 -http://www.slipstick.com/developer/how-to-use-outlooks-vba-editor/

巨集安全性應設定為中。

按鈕幫助 -http://www.howto-outlook.com/howto/macrobutton.htm

編輯:修復了 InStr 行

相關內容