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.
<step="1" title="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.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: |
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 |
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.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: |
Private objLNM As LinkedNoteManager
Private Sub Application_Quit()
Set objLNM = Nothing
End Sub
Private Sub Application_Startup()
Set objLNM = New LinkedNoteManager
End Sub
Sub AddLinkedNote()
objLNM.AddNoteToMsg
End Sub
Sub RemoveLinkedNote()
objLNM.DeleteNoteFromMsg
End Sub |
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.