Ignore Conversations in Outlook 2003

Ignoring Conversation

Happy Memorial Day!

In Outlook 2010 there is a new feature that lets you "ignore" emails in a conversation — existing and future emails are sent to the Deleted Items folder.

This feature is great for inter-office Reply-To-All swarms, chain letters, joke forwards, and other types of email threads you wish would just go away.

Outlook 2003 users are out of luck. You need to use VBA code to mimic this feature. Fear not, I am here for you! Sorry Outlook 2007, you are still out of luck. :)

Identify Conversations

First we'll need a method for identifying conversations. The way I've chosen to do it is using the MailItem.ConversationIndex Property. This property is a 44+ character string which uniquely identifies each email in a thread.

The reason why I say "44+" is because the .ConversationIndex for the first email in a thread is 44 characters, and each reply has some characters appended to the original string. However the leftmost 44 characters always identify the thread.

Ignore Conversation

To keep a log of ignored conversations, I use a Note to record the conversation index of each conversation I want to stop seeing.

The idea is:

  • Select or open an email
  • Grab the ConversationIndex
  • Open or create a custom Note and write the ConversationIndex to it
  • Loop through the Inbox and delete any matching emails in the same thread
Public Const APPNAME As String = "Ignore Conversation"
Public Const DELIMITER As String = ","
Public Const CONVERSATIONINDEX_BASE_LENGTH As Long = 44
Public Const NOTE_INDICATOR As String = "Ignore Conversation Log"

Sub IgnoreConversation()

  On Error GoTo ErrorHandler

  Dim itm As Object
  Dim Msg As Outlook.MailItem
  Dim convIndex As String
  Dim note As Outlook.NoteItem
  Dim olApp As Outlook.Application
  Dim inboxItems As Outlook.Items
  Dim i As Long
  Dim currentMsg As Outlook.MailItem

  ' grab currently selected or open item
  Set itm = GetCurrentItem

  If TypeName(itm) = "MailItem" Then
    Set Msg = itm

    ' close item, it will be deleted later
    If IsInspector(itm) Then
      itm.Close olDiscard
    End If

    ' get base conversation index
    convIndex = Left$(GetConversationIndex(Msg), CONVERSATIONINDEX_BASE_LENGTH)

    ' ----------------------------------
    ' write conversation index to Note
    ' ----------------------------------

    ' first, check if Note already exists
    Set note = GetNote

    If note Is Nothing Then  ' doesn't exist, create it
      Set note = CreateNote
    End If

    ' add conversation index to Note
    Set note = AddToNote(note, convIndex)

    ' ------------------------------------------------------
    ' delete any existing emails w/ same conversation index
    ' ------------------------------------------------------
    Set olApp = Outlook.Application
    Set inboxItems = GetItems(GetNS(olApp), olFolderInbox)

    ' loop backwards because we are deleting
    For i = inboxItems.Count To 1 Step -1
      If TypeName(inboxItems.item(i)) = "MailItem" Then
        Set currentMsg = inboxItems.item(i)

        ' same conversation index, delete it!
        If Left$(GetConversationIndex(currentMsg), CONVERSATIONINDEX_BASE_LENGTH) = convIndex Then
          currentMsg.Delete
        End If

      End If
    Next i

  Else  ' either no message was selected or open
    MsgBox "Please select or open an email before running this code.", vbInformation, APPNAME
  End If

ProgramExit:
  Exit Sub
ErrorHandler:
  MsgBox Err.Number & " - " & Err.Description
  Resume ProgramExit
End Sub

Restore Conversations

We'll need a method for un-ignoring (is that a word?) a conversation, if we change our minds and want to read emails in the thread. Select an item in the Deleted Items folder (which I assume here is part of a thread you've previously ignored) and run this procedure.

Sub RestoreConversation()

  On Error GoTo ErrorHandler

  Dim itm As Object
  Dim Msg As Outlook.MailItem
  Dim convIndex As String
  Dim note As Outlook.NoteItem
  Dim olApp As Outlook.Application
  Dim inboxItems As Outlook.Items
  Dim i As Long
  Dim currentMsg As Outlook.MailItem

  ' grab currently selected or open item
  Set itm = GetCurrentItem

  If TypeName(itm) = "MailItem" Then
    Set Msg = itm

    ' close item
    If IsInspector(itm) Then
      itm.Close olDiscard
    End If

    ' get base conversation index
    convIndex = Left$(GetConversationIndex(Msg), CONVERSATIONINDEX_BASE_LENGTH)

    ' the Note should already exist, because you only try to restore
    ' conversations that were being ignored right????
    Set note = GetNote

    If note Is Nothing Then  ' doesn't exist
      MsgBox "The Conversation Index Log is missing, " & _
             "either there are no conversations being ignored or the log was deleted.", vbCritical, APPNAME
      GoTo ProgramExit
    End If

    ' remove conversation index from Note
    Call RemoveFromNote(note, convIndex)

  Else  ' either no message was selected or open
    MsgBox "Please select or open an email before running this code.", vbInformation, APPNAME
  End If

ProgramExit:
  Exit Sub
ErrorHandler:
  MsgBox Err.Number & " - " & Err.Description
  Resume ProgramExit
End Sub

Helper Functions

These functions are necessary for ignoring conversations and should be placed in a standard module in the Outlook VBA project.

Function GetConversationIndex(Msg As Outlook.MailItem) As String
  GetConversationIndex = Msg.ConversationIndex
End Function

Function GetNote() As Outlook.NoteItem

  Dim olApp As Outlook.Application
  Dim notes As Outlook.Items
  Dim note As Outlook.NoteItem

  Set olApp = Outlook.Application
  Set notes = GetItems(GetNS(olApp), olFolderNotes)

  ' cannot use Restrict Method on Categories, must loop
  For Each note In notes
    If note.Categories = NOTE_INDICATOR Then
      Set GetNote = note
      Exit For
    End If
  Next note

End Function

Function CreateNote() As Outlook.NoteItem
' create new note
  Dim newNote As Outlook.NoteItem

  Set newNote = Outlook.CreateItem(olNoteItem)

  ' set up category string so we can find it later
  With newNote
    .Categories = NOTE_INDICATOR
    .Save
  End With

  Set CreateNote = newNote

End Function

Function AddToNote(note As Outlook.NoteItem, textToAdd As String) As Outlook.NoteItem
' update existing note with text
  With note
    .Body = note.Body & DELIMITER & textToAdd
    .Save
  End With
  Set AddToNote = note
End Function

Function RemoveFromNote(note As Outlook.NoteItem, textToRemove As String) As Outlook.NoteItem
' remove text from note

  Dim removalText As String

  removalText = textToRemove & DELIMITER

  With note
    .Body = Replace(.Body, removalText, "")
    .Save
  End With
  Set RemoveFromNote = note
End Function

GetCurrentItem, IsExplorer, IsInspector, GetItems, GetNS and GetOutlookApp may be found on the Utility Functions page.

Event Handler for Incoming Emails

So now we've got a way to ignore conversations, and restore ignored conversations. Now we need an event handler that is going to check incoming emails to see if they should be ignored, and delete them.

Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()

  Dim olApp As Outlook.Application

  Set olApp = Outlook.Application
  Set Items = GetItems(GetNS(olApp), olFolderInbox)

End Sub

Private Sub Items_ItemAdd(ByVal item As Object)

  On Error GoTo ErrorHandler

  Dim Msg As Outlook.MailItem
  Dim convIndex As String
  Dim note As Outlook.NoteItem

  If TypeName(item) = "MailItem" Then
    Set Msg = item

    ' -----------------------------------------------------------------------------
    ' check Note for conversation index, if it matches then message should be deleted
    ' -----------------------------------------------------------------------------
    Set note = GetNote

    If note Is Nothing Then  ' no ignored conversations, just exit
      GoTo ProgramExit
    End If

    ' grab conversation index
    convIndex = Left$(GetConversationIndex(Msg), CONVERSATIONINDEX_BASE_LENGTH)

    If InStr(note.Body, convIndex) > 0 Then  ' delete it!
      Msg.Delete
    End If

  End If

ProgramExit:
  Exit Sub
ErrorHandler:
  MsgBox Err.Number & " - " & Err.Description
  Resume ProgramExit
End Sub

All we need to do is check if the incoming email's ConversationIndex is found in our custom Note (which it would if we ran the IgnoreConversation procedure on the thread), and if it does, delete it.

This code should be pasted into the ThisOutlookSession module, then Outlook should be restarted.

Recommendation

I recommend you assign the IgnoreConversation and RestoreConversation procedures to toolbar buttons in the main Explorer window. You can do it manually or using VBA. Then when that annoying email comes in, you'll be ready to click the Ignore button and get back to doing what you love — goofing off instead of working.

Next time we'll review some code that mimic's Gmail's Mute feature. Stay tuned!

About JP

I'm just an average guy who writes VBA code for a living. This is my personal blog. Excel and Outlook are my thing, with a sprinkle of Access and Word here and there. Follow this space to learn more about VBA. Keep Reading »

Share This Article:

Share and bookmark this articledelicious buttonfacebook buttonlinkedin buttonstumbleupon buttontwitter button

Related Articles:



comment bubble 7 Comments on Ignore Conversations in Outlook 2003:

  1. kach up writes:

    Hello average guy,
    I use ouutlook 2003 to read forum messages. Outlook doesn't seem to work ignoring certain messages for VBulleltin what ever its called it dumps all messages if created with the builtin rules feature. So i'm after a VBA script to ignore certain user in the same forum. His rants and hilights of word annoys the crap out of me lol. how can i do this with a userform
    regards kach

    • JP writes:

      Why don't you do this through the forum? vBulletin has an "ignore user" feature, you should first find out if the forum offers that feature before trying to use VBA.

      • kach writes:

        The vBulletin ignore feature doesn't work. Tried it many times. I ask the forum host he said it doesn't work never has been able to ignore post if someone else responds or quotes the user I'm trying to ignore.

        • JP writes:

          OK. I don't know why you would need a userform for this. The code in the article should be sufficient. You could also set up a rule that sends any email with certain words (ex: the name person you want to ignore) in the body to the Deleted Items folder.

        • kach writes:

          Thank you JP, I don't want to delete any of the thread(s) i just want his post moved to the junk folder. The other forum users are smart enough not to quote his dribble as i guess it annoys them as well .or. when they do they do it in such away that HE gets the message about his annoying hilght dribbles. (ex: *I have* _never_ever_ *DONE* that _AND_ *never*ever*) etc its just annoying

        • JP writes:

          I think you've made it very clear that you don't like the guy — there's no need to mention it again and no need to get specific.

          The Junk Folder may not work the way you need it. It may require you to flag each incoming message as Junk, which is not what you want.

  2. kach writes:

    What ever. I don't like his dribbley long winded comments. I didn't say anything about him anywhere.

    I'm over this

This article is closed to new comments. Why?
Random Data Generator