delete previous e-mails with same number in subject

A

amsmith

Can anyone tell me how to write a rule that will delete previous e-mails with
the same number in the subject? I receive e-mails with subjects similar to
the following: "XYZ Company Issue #5506384." I would like Outlook to only
keep the most recent version of the e-mail for that issue. The e-mails are
sent by various employees from the company and the subject may have
additional words after the issue number. Any help would be greatly
appreciated!
 
K

Ken Slovak - [MVP - Outlook]

No rule alone could do that. You would need to define a rule that called a
procedure in your VBA project and use that procedure to do what you wanted.
The procedure would look something like this:

Sub KillOlderConversationItems(MyMail As Outlook.MailItem)
Dim sConversationTopic As String
Dim sConversationIndex As String
Dim oFolder As Outlook.MAPIFolder
Dim colItems As Outlook Items
Dim colMyItems As Outlook.Items
Dim oNS As Outlook.NameSpace
Dim lCount As Long
Dim i As Long
Dim oMail As Outlook.MailItem

sConversationTopic = MyMail.ConversationTopic
sConversationIndex = MyMail.ConversationIndex

Set oNS = Application.GetNameSpace("MAPI")
Set oFolder = oNS.GetDefaultFolder(olFolderInbox)
Set colItems = oFolder.Items
Set colMyItems = colItems.Restrict("[ConversationTopic] = " & _
Chr(34) & sConversationTopic & Chr(34)

lCount = colMyItems.Count
For i = lCount To 1 Step -1
Set oMail = colMyItems.Item(i)
If Len(oMail.ConversationIndex) < Len(MyMail.ConversationIndex) Then
oMail.Delete
End If
Next

Set oMail = Nothing
Set oNS = Nothing
Set colMyItems = Nothing
Set colItems = Nothing
Set oFolder = Nothing
End Sub

That "script" would be called from your rule.

This sub as shown doesn't do any error handling or checking to see if every
item is a MailItem. It also will filter on items that have identical
ConversationTopic property values, which should do what you want as long as
all the items are part of a conversation thread. If you want items that
aren't associated that just have the same number in the Subject you'd have
to loop over the entire collection in the folder and check for Subject
containing that number for each item.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top