Removing Duplicate Notes from Outlook

Here is a simple macro to remove duplicate note items from Outlook. Notes are much simpler than contacts or events, because either they are identical, or they are two different notes.

Instructions
1. From Outlook, open your macro editor. (Either press alt-F11 or select Tools, Macro, Visual Basic Editor.)
2. In the macro editor window, select Insert, Module. This will create a text editor window into which you can paste the macro.
3. In the text editor window, paste in the code below. (I recommend you review the code to be sure it’s doing what you want.)
4. You can run the code by placing your cursor anywhere in the code window between the “Sub” and “End Sub” statements and pressing F5. Optionally, you can close the Visual Basic window, then select Tools, Macro, Macros…, and “Run” RemoveDuplicateNotes.

Here is the code for the macro. Hopefully, it is useful to someone. Please let me know if you have any problems so I can correct make an effort to correct the macro.

IMPORTANT A regular copy/paste should work correctly. However, you may experience issues with line breaks that prevent the macro from working. If this is the case, the Outlook VB editor will make it abundantly clear what lines are invalid, so it should be pretty easy to fix rogue line wrapping.

':::::::::::::::::: Macro Begins Here; Copy this line and everything below
Sub RemoveDuplicateNotes()
    Dim olApp As Outlook.Application
    Dim olNote1 As Outlook.NoteItem
    Dim olNote2 As Outlook.NoteItem
    Dim olItems As Outlook.Items
    Dim olNS As Outlook.NameSpace

    Set olApp = New Outlook.Application
    Set olNS = olApp.GetNamespace("MAPI")
    Set olItems = olNS.GetDefaultFolder(olFolderNotes).Items
    olItems.Sort ("Subject")
    Dim DeleteCount As Integer
    Dim z As Integer
    DeleteCount = 0

    For z = olItems.Count To 2 Step -1
        Set olNote1 = olItems.Item(z)
        Set olNote2 = olItems.Item(z - 1)
        DoEvents
        If InStr(1, olNote1.Subject, "Pay Attention") Then
            Debug.Print olNote1.Subject
            Debug.Print "Create Time: " & olNote1.CreationTime
            Debug.Print "Mod time:  " & olNote1.LastModificationTime
        End If
        If olNote1.Body = olNote2.Body Then
            olNote1.Delete
            Debug.Print "Note item " & Left(olNote2.Subject, 25) & "..." & " deleted"
            DeleteCount = DeleteCount + 1
        End If
    Next
    MsgBox DeleteCount & " duplicate Outlook Notes have been removed"
End Sub

':::::::::::::::::: Macro Ends Here

* This macro was developed using Outlook 2003. It works very well for me, but I make no guarantee it will work for you. Please review the code before running to be sure it doesn’t perform some task you are not expecting. Also, I strongly recommend backing up your Outlook data (usually a PST file) before running the macro.

Please leave feedback letting me know whether or not it works for you. If you have problems with it, please let me know that as well.

Post A Comment

You must be logged in to post a comment.