<

Creating Linked Notes in Outlook 2007

Published on
15,719 Points
5,119 Views
6 Endorsements
Last Modified:
Awarded
Community Pick
Scenario.

You want the ability to have a note linked to an Outlook message.  The note might contain a list of actions to take prior to responding to the message, contacts to make to collect information for a response, your thoughts on the message, or any action/detail you want to have tied to that message.  Outlook has the ability to create notes, but not to link them to a message.  Unlike other Outlook item types (e.g. appointments, tasks) which have a body field for notes, messages only have the message body.  Of course you could edit the message body and place your notes there, but that means they become part of the message and will be sent with the message if you forget to remove them.  Or you could create a note and embed a link to it in the message.  That requires a number of extra steps and as with having the notes in the message itself you will probably want to remove the link before sending the message.  Another option is to turn the message into a task.  That's fine if you want it to appear as a task, but may not work well if you simply want to have some notes associated with the message.  

Solution.

Linked Notes Manager, the code presented in this article, gives you the ability to create a note linked to a message.  Once created, a linked note will pop up every time you open the message it's linked to.  A note can be added to/removed from  messages without regard to whether they are opened or closed.  Linked notes are stored in a separate sub-folder under Notes.  In addition to editing or deleting a note, you can also add a column to any Outlook view to see which items have a linked note.  

Requirements.

Linked Notes Manager requires Outlook 2007.

Instructions.

1. Adding the Code to Outlook



a.  Start Outlook.
b.  Click Tools > Macro > Visual Basic Editor (ALT+F11).
c.  If not already expanded, expand Microsoft Office Outlook Objects, then expand Class Modules.
d.  Right-click on Class Modules and select Insert > Class Module
e.  Look in the Properties panel.
f.   Change the name of the new class module to LinkedNotesManager.
g.  Copy the code in the snippet below and paste it into the right-hand pane of the VB Editor window.
h.  Edit the code as needed.  I included comments wherever something needs to or can change.
Option Explicit

'*** Constants
Const CLASSNAME = "Linked Notes Manager"
Const VERSION = "v1.0"
Const LINKEDNOTEFOLDER = "Linked Notes"
    'The name of the folder that the linked notes will go in'
Const LINKPROPERTY = "LinkedNote"
    'The name of the item property containing the link to the note'
Const FORCEONTOP = False
    'True | False'
    'If True, the notes will appear on top of the linked item'
    'If False, the note appears behind the linked item'
Const msoControlButton = 1
Const msoButtonIconAndCaption = 3

'*** Class variables
Private WithEvents olkApp As Outlook.Application, _
        WithEvents olkInspectors As Outlook.Inspectors, _
        olkInspector As Outlook.Inspector, _
        olkNotesFolder As Outlook.Folder

Private Sub Class_Initialize()
    On Error Resume Next
    Set olkNotesFolder = Session.GetDefaultFolder(olFolderNotes).Folders(LINKEDNOTEFOLDER)
    If TypeName(olkNotesFolder) = "Nothing" Then
        Set olkNotesFolder = Session.GetDefaultFolder(olFolderNotes)
        Set olkNotesFolder = olkNotesFolder.Folders.Add(LINKEDNOTEFOLDER, olFolderNotes)
    End If
    Set olkApp = Application
    Set olkInspectors = olkApp.Inspectors
    On Error GoTo 0
End Sub

Private Sub Class_Terminate()
    Set olkApp = Nothing
    Set olkInspectors = Nothing
    Set olkInspector = Nothing
    Set olkNotesFolder = Nothing
End Sub

Private Sub olkApp_ItemContextMenuDisplay(ByVal CommandBar As Office.CommandBar, ByVal Selection As Selection)
    Dim objButton As Object, _
        olkItem As Object, _
        bolLinked As Boolean
    Set objButton = CommandBar.Controls.Add(msoControlButton)
    If Selection.Count = 1 Then
        Set olkItem = Selection.Item(1)
        If olkItem.Class = olMail Then
            bolLinked = IsLinked(olkItem)
            With objButton
                .Style = msoButtonIconAndCaption
                .Caption = IIf(bolLinked, "Remove", "Add") & " Linked Note"
                .Parameter = Selection.Item(1).EntryID
                .FaceId = IIf(bolLinked, 348, 347)
                .OnAction = IIf(bolLinked, "Project1.ThisOutlookSession.RemoveLinkedNote", "Project1.ThisOutlookSession.AddLinkedNote")
            End With
        End If
    End If
End Sub

Private Sub olkInspectors_NewInspector(ByVal Inspector As Inspector)
    Dim olkMsg As Outlook.MailItem, _
        olkNote As Outlook.NoteItem, _
        olkProp As Outlook.UserProperty
    On Error Resume Next
    If Inspector.CurrentItem.Class = olMail Then
        Set olkMsg = Inspector.CurrentItem
        Set olkProp = olkMsg.UserProperties.Find(LINKPROPERTY, True)
        If TypeName(olkProp) = "UserProperty" Then
            Set olkNote = Session.GetItemFromID(olkProp.Value)
            If TypeName(olkNote) <> "Nothing" Then
                olkNote.Display FORCEONTOP
            Else
                MsgBox "The note linked to this item could not be found.", vbInformation + vbOKOnly, CLASSNAME
            End If
        End If
    End If
    Set olkMsg = Nothing
    Set olkNote = Nothing
    Set olkProp = Nothing
    On Error GoTo 0
End Sub

Private Function IsLinked(ByRef olkItem As MailItem) As Boolean
    Dim olkProp As Outlook.UserProperty
    Set olkProp = olkItem.UserProperties.Find(LINKPROPERTY)
    If TypeName(olkProp) = "Nothing" Then
        IsLinked = False
    Else
        If olkProp.Value = "" Then
            IsLinked = False
        Else
            IsLinked = True
        End If
    End If
End Function

Public Sub AddNoteToMsg()
    Dim olkMsg As Object, _
        olkNote As Outlook.NoteItem, _
        olkProp As Outlook.UserProperty
    On Error Resume Next
    Select Case TypeName(Application.ActiveWindow)
        Case "Explorer"
            Set olkMsg = Application.ActiveExplorer.Selection(1)
        Case "Inspector"
            Set olkMsg = Application.ActiveInspector.CurrentItem
    End Select
    If olkMsg.Class = olMail Then
        Set olkNote = olkNotesFolder.Items.Add()
        olkNote.Body = "Linked to: " & olkMsg.Subject
        olkNote.Save
        Set olkProp = olkMsg.UserProperties.Add(LINKPROPERTY, olText)
        olkProp.Value = olkNote.EntryID
        olkMsg.Save
        olkNote.Display
    End If
    Set olkProp = Nothing
    Set olkNote = Nothing
    Set olkMsg = Nothing
    On Error GoTo 0
End Sub

Public Sub DeleteNoteFromMsg()
    Dim olkMsg As Outlook.MailItem, _
        intIndex As Integer
    On Error Resume Next
    Select Case TypeName(Application.ActiveWindow)
        Case "Explorer"
            Set olkMsg = Application.ActiveExplorer.Selection(1)
        Case "Inspector"
            Set olkMsg = Application.ActiveInspector.CurrentItem
    End Select
    If olkMsg.Class = olMail Then
        For intIndex = 1 To olkMsg.UserProperties.Count
            If olkMsg.UserProperties.Item(intIndex).Name = LINKPROPERTY Then
                olkMsg.UserProperties.Remove intIndex
                olkMsg.Save
            End If
        Next
    End If
    On Error GoTo 0
    Set olkMsg = Nothing
End Sub

Open in new window

i.  Double-click on the ThisOutlookSession module at the top of the Project panel.
j.  Copy the code in the snippet below and paste it into the right-hand pane of the VB Editor window.  If yu already have code in ThisOutlookSession, then instead of simply copying and pasting you will have to integrate this code into that you already have.
Private objLNM As LinkedNotesManager

Private Sub Application_Quit()
    Set objLNM = Nothing
End Sub

Private Sub Application_Startup()
    Set objLNM = New LinkedNotesManager
End Sub

Sub AddLinkedNote()
    objLNM.AddNoteToMsg
End Sub

Sub RemoveLinkedNote()
    objLNM.DeleteNoteFromMsg
End Sub

Open in new window

k.  Click the diskette icon on the toolbar to save the changes
l.  Close the VB Editor
m.  Click Tools > Trust Center.
n.  Select Macro Security.
o.  For this code to work macro security must be set to one of the three bottom options, one of the lower two if the code is not signed.

2. Restarting Outlook


a.  Close Outlook.
b.  Restart Outlook.
c.  When Outlook restarts you should see a pop-up dialog-box titled "Microsoft Office Outlook Security Notice" warning that ThisOutlookSession contains macros and asking if you want to enable or disable them.  For this solution to work you must select "Enable Macros".  This box will be displayed each time Outlook starts.

3. Using Linked Notes Manager


Creating notes.  You can create a linked note in two ways.  First, without opening a message, right-click on it and select "Add Linked Note".  Second, with a message open onscreen, click the Developer tab, then click Macros and select "ThisOutlookSession.AddLinkedNote".  No matter which approach you took, a yellow Outlook note should appear onscreen with the title of the message you're linking it to already filled in.  Add whatever you want to the note and then close it.  The next time you open the message the note will open with it.  

Removing notes.  There are two ways to remove a note.  First, without opening the message, right-click on it and select "Remove Linked Note".   Second, with a message open onscreen, click the Developer tab, then click Macros and select "ThisOutlookSession.RemoveLinkedNote".  When removing a note the code does not delete the actual note.  Instead, it removes the linking property leaving the note intact in case you want to keep it.  Notes are kept in the folder named "Linked Notes" under Outlook's default Notes folder.

Viewing notes.  Each time you open a message with a linked note the note opens too.  You can edit the note, add to it, or simply ignore it.  Notes do not close when the message closes, so you will need to remember to close the notes window separately.

Links to Other BlueDevilFan Articles

1. Extending Outlook Rules via Scripting
2. Importing and Exporting Outlook 2007 Categories
3. Outlook 2007 Corporate Categories System
4. Automatically Printing/Saving Emails/Attachments in Outlook
5. Avoiding Blank Subject Lines in Outlook
6. Never Again Forget to Add that Attachment to your Outlook Email
7. Enhancing Outlook 2007 Meeting Reminders
6
Author:David Lee
Ask questions about what you read
If you have a question about something within an article, you can receive help directly from the article author. Experts Exchange article authors are available to answer questions and further the discussion.
Get 7 days free