<

Creating Linked Notes in Outlook 2007

Published on
15,612 Points
5,012 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
Comment
Author:David Lee
  • 5
  • 3
8 Comments
 

Expert Comment

by:trevor110
Thanks for doing all this.  Unfortunatelys I've encountered a small problem in adding the code.
I'm using a newly installed copy of Outlook 2007 with Business Contact Manager and a couple of Add-ins (AVG anti-Spam bar & PDF Converter bar)
First set of code was entered OK.
When I came to enter the second set of code, there were just two lines of code already in the window, with the cursor sitting between them.  Wasn't sure whether to enter code between or instead of those two lines (which I assumed to be a default reading for new coding.  I deleted those two lines and inserted your code in their place.

When I tried to run it first time, I got an error (can't remember actual wording) along the lines of "LinkedNoteManager" not found.  Added an "s" in the middle of the name at the end of "Note".
Then it gave a warning about "Expecting user-defined something - not an object".

Have now deleted all code, but still getting a general 'Macros' warning on start-up (which didn't exist before) so it clearly thinks there is something there.

Was going to retry by adding your second section of code between the 'default' two lines of code that existed when I first opened ThisOutlookSession - but of course they are no longer there!

Any advice would be appreciated.
Thanks in anticipation, Trevor
0
 
LVL 76

Author Comment

by:David Lee
You're welcome.  Glad you found it a useful enough concept to give it a try.

Do you have any code in Outlook?  Not just in ThisOutlookSession, but in any module.
0
 

Expert Comment

by:trevor110
Hi, Thanks for the extremely rapid response.

The answer to your question is "Not as far as I can tell".  I have to admit, I'm on the limits of my knowledge with VBA modules, etc. (tho' I've previously done some macros and customisation in Word 2003 & earlier).

When I open VBA, it still shows "Linked Notes Manager" as a Project, with ThisOutlookSession as a child, and I can't work out how to remove the Project (if I need to).

But, IF my problem was just that I shouldn't have deleted the two default lines of code in the OutlookSession window, I'd like to retry Linked Notes, if you could tell me what the default lines were.  And IF that's all I'm likely to need to redo - I know it's difficult to tell from a distance!
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 76

Author Comment

by:David Lee
I've no idea what lines were there.  They didn't have anything to do with Linked Notes unless you copied them in from the code above.  What I was going to suggest is deleting the file that Outlook stores all macro code in to give you a fresh start.  You should only do that though if you are SURE that there isn't any macro code in Outlook that you want to keep.  Of course to be safe you can keep a copy of the file and restore it later.  Do you want to give that a try?
0
 

Expert Comment

by:trevor110
Yes.  Happy to try that thanks.  As you say, I can always restore it.
Sorry if I thought you might have physic powers (!): I realised they had nothing to do with Linked Notes, but - as the window opened with the cursor between those two lines ready for typing - I had assumed it was two lines that Outlook always included by default when you first opened that object.  Obviously not!
0
 

Expert Comment

by:trevor110
P.S. I subsequently came across what appears to be an earlier version of this module, in http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_23983438.html?sfQueryTermInfo=1+10+2007+30+add+email+messag+note+outlook.
There you said:
"Copy the code between the THISOUTLOOKSESSION tags and paste it into the right-hand pane of the editor window."
I thought maybe it was those 'tags' that I had erroneously deleted, and had thought you might know what they are - or does that not apply to this later version of the code?
0
 
LVL 76

Author Comment

by:David Lee
trever110,

Would you mind opening a question on this issue so we can continue the troubleshooting there?  I'm concerned about cluttering the article and comments with troubleshooting on one specific issue.  If that's okay, then don't worry about the point value.  I'm not looking to score points, just tying to keep the article comments from getting too confusing.
0
 

Expert Comment

by:trevor110
Done! Apologies for cluttering up here! Likewise, I'm not bothered about the point value!
Thanks, Trevor
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Join & Write a Comment

Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Discover the basics of using Outlook 2016 from office 365.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month