Simulate Gmail's Mute Feature in Outlook 2003

In Ignore Conversations in Outlook 2003 I mentioned that we'd be writing code to simulate Gmail's Mute feature in Outlook.

From Google's KB:

If you're subscribed to a mailing list, you've no doubt been subjected to the 'thread that just won't die!' If you're part of a long message conversation that isn't relevant, you can 'mute' the conversation to keep all future additions out of your inbox.

By selecting a conversation and clicking Mute in the 'More actions' drop-down menu, or by using the 'm' shortcut key, new messages added to the conversation bypass your inbox so that the conversation stays archived. If your address appears in the to or cc field, though, the conversation will pop back into your inbox ready for your attention.

Implementing this feature using VBA uses nearly the exact same code as the Ignore Conversations code, with one change in the event handler to handle when an 'ignored' conversation is sent directly to you via the To or Cc field.

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
  Dim msgRecips As Outlook.Recipients
  Dim msgRecip As Outlook.Recipient

  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?
      ' check if recipient is in the To or Cc field
      Set msgRecips = Msg.Recipients
      For Each msgRecip In msgRecips
        If ((InStr(msgRecip.name, Outlook.Session.CurrentUser) > 0) And _
            (msgRecip.Type <> olTo Or msgRecip.Type <> olCC)) Then
          Msg.Delete
          Exit For
        End If
      Next msgRecip

    End If

  End If

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

So all you need to do to use this code instead of the Ignore Conversations code is to visit that post, copy all the code and paste into Outlook's VB Editor, but use the above event handler instead. See Where do I put my Outlook VBA code? if you need to know where to put event handlers and 'regular' code (like functions).

The only other change I would recommend is when creating the toolbar buttons for the functions to ignore and restore conversations, I would change the button name to "Mute" instead of "Ignore". This would more accurately represent the function of the code.

Add Button to Outlook Toolbar Manually
Add Button to Outlook Toolbar Using VBA

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:



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