A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

delete previous e-mails with same number in subject



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old December 27th 07, 10:45 PM posted to microsoft.public.outlook.program_vba
amsmith
external usenet poster
 
Posts: 1
Default delete previous e-mails with same number in subject

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!
Ads
  #2  
Old December 28th 07, 03:20 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default delete previous e-mails with same number in subject

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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"amsmith" wrote in message
...
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!


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete tasks from mail subject vbadude_sl Outlook and VBA 4 March 1st 07 03:46 PM
no subject e mails, how do I deal with them? T5 Outlook - General Queries 8 November 25th 06 06:45 PM
Delete future recurring appointments, retain previous. Blick TX Outlook - Calandaring 1 June 16th 06 04:20 PM
New message To, CC, BCC and Subject fields don't accept 'delete' [email protected] Outlook - General Queries 3 May 25th 06 08:34 PM
Date: and Subject: Can I delete/hide them? Richelle Outlook - General Queries 4 February 7th 06 03:57 PM


All times are GMT +1. The time now is 07:56 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.