Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Is there any way that we can add short notes to invividual emails in outlook.

Hi,

Is there any way that we can add short notes to invividual emails in outlook.
So when double click on the mail i can see those notes?

Outlook 2007.

Can any code add this option to outlook. Without any 3rd party option.

Regards
Sharath
Avatar of tigermatt
tigermatt
Flag of United Kingdom of Great Britain and Northern Ireland image

Sharath,

This option is not available in Outlook, and it is far beyond the scope of a Macro to add this. It would be the job of an expensive third-party add-on to achieve this, as it is not something Outlook was designed to do.

The best I can suggest is the features in Tasks, Contact and Calendar items, whereby you can click the 'Add Item' button to add an email or contact to a Task, Calendar or Contact.

Matthew.
Hi, Sharath.

I agree with Matthew that this option is not available in Outlook.  A 3rd-party add-on is certainly better suited to providing this capability, but I don't think it's beyond the scope of a macro.  I think there are a couple of ways to do this with a macro.  

1.  Outlook messages have a Contacts property which can be set to a particular contact item.  You could put the note in the body of the contact, connect the contact to the message via the Contacts property, then check for and open that contact each time the item is opened.  The contact link will go out with the message, but the recipient cannot use it to access the contact, so your note is safe.  The only real downside is that you have to remember to connect a contact to the message.  

2.  All Outlook items have the ability to store additional data in what is known as user-defined properties (UDP).  With a bit of scripting you could display a dialog-box, enter some notes, and store them in a UDP.  With a bit more code you could check items when they are opened to see if they have the UDP.  If they do, then you could display the notes in a pop-up dialog.  The downside of this solution is that the notes will go with the message to the recipient.  They could potentially find that UDP and see what you wrote.  That'd probably be a bad thing.

3.  Another possibility, really a twist on #2, is to save the note outside of the message and include a link to it in the UDP.  For example, the note could go into an actual Outlook note and a link to the note placed in the UDP.  That wouldn't be very difficult to do.  In fact, the code in the snippet shows how easy it is.  This is strictly proof of concept.  Open a message and run AddNoteToMsg.  It will display a standard Outlook note (you can find it in your Notes folder) and embed a link to that note in a UDP of the open message.  You can then open the message at any time and run DisplayLinkedItem.  That block of code will get the address of the note from teh messages UDP and display it onscreen.  The only caveats are that the note must remain in the folder it's created in, in a production version of this I'd advocate creating a folder just for these linked notes, and I've not designed a means of cleaning up notes associated with deleted messages.
Sub AddNoteToMsg()
    Dim olkMsg As Outlook.MailItem, olkNote As Outlook.NoteItem
    Set olkMsg = Application.ActiveInspector.CurrentItem
    Set olkNote = Application.CreateItem(olNoteItem)
    olkNote.Body = "Linked to: " & olkMsg.Subject
    olkNote.Save
    olkMsg.UserProperties.Add "LinkedNote", olText
    olkMsg.UserProperties.Item("LinkedNote").Value = olkNote.EntryID
    olkMsg.Save
    olkNote.Display
End Sub
 
Sub DisplayLinkedNote()
    Dim olkMsg As Outlook.MailItem, _
        olkNote As Outlook.NoteItem, _
        olkProp As Outlook.UserProperty
    Set olkMsg = Application.ActiveInspector.CurrentItem
    Set olkProp = olkMsg.UserProperties.Find("LinkedNote", True)
    If TypeName(olkProp) = "UserProperty" Then
        Set olkNote = Session.GetItemFromID(olkProp.Value)
        olkNote.Display
    End If
    Set olkMsg = Nothing
    Set olkNote = Nothing
    Set olkProp = Nothing
End Sub

Open in new window

BDF - that's neat!

-Matt
Thanks, Matt.  I'm working on an improved version that I'll post shortly.
Here's an improved version that opens a note, if the item has one, automatically.  This version only works in Outlook 2007.  Follow these instructions to use it.

1.  Open Outlook
2.  Press ALT+F11 to open the VB editor
3.  If not already expanded, expand Project1
4.  Right-click on Class Modules and select Insert > Class Module
5.  Select the newly inserted module.  Unless you already have one or more class modules, then the new module will be named Class1
6.  In the Properties pane, click on name and change it to LinkedNoteManager
7.  Copy the code between the CLASS MODULE CODE tags and paste it into the right-hand pane of the editor window
8.  Double-click on the ThisOutlookSession module
9.  Copy the code between the THISOUTLOOKSESSION tags and paste it into the right-hand pane of the editor window.  If you already have subroutines with these names, then add the code from these routines into them

Here's how to use this.

1.  With a message open onscreen
2.  Click the Developer tab
3.  Click the Macros button
4.  Run the ThisOutlookSession.LNMAddNote macro
5.  Fill in and save the note

The class module also checks items as they're opened looking to see if they have a note linked to them.  If they do, then the note is opened when the item is opened.
'<CLASS MODULE CODE>'
Option Explicit
 
'*** Constants
Const CLASSNAME = "Linked Note Manager"
Const VERSION = "v1.0"
 
'*** 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("Linked Notes")
    If TypeName(olkNotesFolder) = "Nothing" Then
        Set olkNotesFolder = Session.GetDefaultFolder(olFolderNotes)
        Set olkNotesFolder = olkNotesFolder.Folders.Add("Linked Notes", 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 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("LinkedNote", True)
        If TypeName(olkProp) = "UserProperty" Then
            Set olkNote = Session.GetItemFromID(olkProp.Value)
            If TypeName(olkNote) <> "Nothing" Then
                olkNote.Display
            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
 
Public Sub AddNoteToMsg()
    Dim olkMsg As Object, _
        olkNote As Outlook.NoteItem, _
        olkProp As Outlook.UserProperty
    On Error Resume Next
    Set olkMsg = Application.ActiveInspector.CurrentItem
    If olkMsg.Class = olMail Then
        Set olkNote = olkNotesFolder.Items.Add()
        olkNote.Body = "Linked to: " & olkMsg.Subject
        olkNote.Save
        Set olkProp = olkMsg.UserProperties.Add("LinkedNote", olText)
        olkProp.Item("LinkedNote").Value = olkNote.EntryID
        olkMsg.Save
        olkNote.Display
    End If
    Set olkProp = Nothing
    Set olkNote = Nothing
    Set olkMsg = Nothing
    On Error GoTo 0
End Sub
'</CLASS MODULE CODE>'
 
'<THISOUTLOOKSESSION CODE>'
Private olkLNM As LinkedNoteManager
 
Private Sub Application_Quit()
    Set olkLNM = Nothing
End Sub
 
Private Sub Application_Startup()
    Set olkLNM = New LinkedNoteManager
End Sub
 
Sub LNMAddNote()
    olkLNM.AddNoteToMsg
End Sub
'</THISOUTLOOKSESSION CODE>'

Open in new window

I should also have mentioned that this version creates a separate folder for the linked notes.  That folder is under the default Notes folder.
Avatar of bsharath

ASKER

Thank U really seems perfect...
I have done all as you have said. Now when i select a mail and run a macro i get a notes box. I have typed in data and have an X to close. Will it get saved?

But when i reopen the mail it does not show me the notes. Now where can i find all the notes?

When opened mail it does not open the notes...
Thank U really seems perfect...
I have done all as you have said. Now when i select a mail and run a macro i get a notes box. I have typed in data and have an X to close. Will it get saved?

But when i reopen the mail it does not show me the notes. Now where can i find all the notes?

When opened mail it does not open the notes...
"Will it get saved?"
Yes, the notes are automatically saved.

"But when i reopen the mail it does not show me the notes. Now where can i find all the notes?"
The notes should be in a folder named "Linked Notes" under your Notes folder.  Are you sure the note didn't open?  It seems to open behind the message most of the time.  
I tried .
What i did is.
Selected a mail and ran the macro it opens a notes box. I enter data and click on the X close mark.
After which i cannot see the notes. Does not open when the mail is opened and cannot find any "Linked Notes"

I click on the notes and there are "0" notes
I tried .
What i did is.
Selected a mail and ran the macro it opens a notes box. I enter data and click on the X close mark.
After which i cannot see the notes. Does not open when the mail is opened and cannot find any "Linked Notes"

I click on the notes and there are "0" notes
Which macro are you running, the first one I posted or the last one?
The last one
ID: 23170878
Try closing and restarting Outlook.
I tried the same at home and now i can see the "Linked notes" folder in notes.
But when i open the mail it does not show the notes
Is there something that i am doing wrong...
I see all the notes that i created. Now how are they linked between each other, The messaage and the notes?
"But when i open the mail it does not show the notes"
Are you sure the notes aren't opening behind the message?  

"Is there something that i am doing wrong..."
It's hard to answer that question without being able to see what's happening.  If the code is running, which it must be if you can add notes, then I don't know how the notes can fail to appear.

"I see all the notes that i created."
Does that mean you see them in the Linked Notes folder or are they popping up now?

"Now how are they linked between each other, The messaage and the notes?"
They are linked via the note's EntryID property.  When you add a note it creates a note, saves it to the Linked Notes folder, then stores that note's EntryID (a unique idenitifier) in a user property of the message.  When you open a message, the code checks to see if the linking user property exists.  If it does, then it gets its value and uses it to opening the associated note.
"I see all the notes that i created."
I can see all of them in linked notes


I dont get the notes opened. When i open a mail
Is there something to do with Html settings or internal or external mails only it works or permissions

>>5.  Fill in and save the note
Is there something i need to save the notes?

I have put in 2 portions of the code little in this Thisotlooksession and little in class module.
"Is there something to do with Html settings or internal or external mails only it works or permissions"

No, it doesn't have anything to do with any of these things.  The code doesn't care about what format the message is, where it came from, or any permissions.  Are you actually opening the messages or just looking at them in the reading pane?  If the latter, then they have to be opened for the code to work.
Notes are saved automatically.  So is the link in the message to its note.
I am opening the mail to the full screen but notes does not popup...
I am able to view all that i created in the Linked notes folder. but dont get them opened when i open the mail

is there any way i can troubleshoot on this...
Yes, we can troubleshoot.  Let's start with this.

1.  Open Outlook's code editor (ALT+F11)
2.  Open the class module containing this code.
3.  Scroll down until you see the subroutine olkInspectors_NewInspector
4.  In that subroutine comment out (place an apostrophe before the first character) these two lines
    On Error Resume Next
    On Error GoTo 0
5.  Close and restart Outlook
6.  Open a message with a linked note and let me know what happens
>>3.  Scroll down until you see the subroutine olkInspectors_NewInspector

I cannot find this.
When i search in  this page i get this line in the first code. Should i use the first code too?
Look back at the code I posted in ID: 23170878.  Are you saying that when you look at the code you have in your class module in Outlook that you cannot find the code that appears on line #33 of that post?
I get this after commenting these 2 lines

---------------------------
Microsoft Visual Basic
---------------------------
Object variable or With block variable not set
---------------------------
OK   Help  
---------------------------

Attached is the code that i changed
Is this right?
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("LinkedNote", True)
        If TypeName(olkProp) = "UserProperty" Then
            Set olkNote = Session.GetItemFromID(olkProp.Value)
            If TypeName(olkNote) <> "Nothing" Then
                olkNote.Display
            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

Open in new window

Yes, that's right.  The error probably occurred on line #8 of that block of code.  That would mean that the link to the note did not get stored in the message item.  Ok, remove the apostrophes from those two lines

Find the code in the class module that matches what you see on line 56 of the post ID: 23170878.  Comment out the same two lines in this sub.  Now, close and restart Outlook, then try adding a note to an item that does not already have a note.  Let me know what happens.
I get this

---------------------------
Microsoft Visual Basic
---------------------------
Object variable or With block variable not set
---------------------------
OK   Help  
---------------------------


Public Sub AddNoteToMsg()
    Dim olkMsg As Object, _
        olkNote As Outlook.NoteItem, _
        olkProp As Outlook.UserProperty
    'On Error Resume Next
    Set olkMsg = Application.ActiveInspector.CurrentItem
    If olkMsg.Class = olMail Then
        Set olkNote = olkNotesFolder.Items.Add()
        olkNote.Body = "Linked to: " & olkMsg.Subject
        olkNote.Save
        Set olkProp = olkMsg.UserProperties.Add("LinkedNote", olText)
        olkProp.Item("LinkedNote").Value = olkNote.EntryID
        olkMsg.Save
        olkNote.Display
    End If
    Set olkProp = Nothing
    Set olkNote = Nothing
    Set olkMsg = Nothing
    'On Error GoTo 0
End Sub

Open in new window

What line?
It goes here
Sub LNMAddNote()
That doesn't make sense.  If it fails at that point, then it would never have created any notes.  Yet apparently it has.  Did you close and restart Outlook after making the last change?
Yes i restarted the machine as well.
I have tried in multiple machines and get this
---------------------------
Microsoft Visual Basic
---------------------------
Run-time error '91':

Object variable or With block variable not set
---------------------------
OK   Help  
---------------------------

and this

---------------------------
Microsoft Visual Basic
---------------------------
Object variable or With block variable not set
---------------------------
OK   Help  
---------------------------

I have the code in this snippet  ID: 23170878
In a call module and thisoutlooksession
When run after selecting a mail i get these error messages
Yes i restarted the machine as well.
I have tried in multiple machines and get this
---------------------------
Microsoft Visual Basic
---------------------------
Run-time error '91':

Object variable or With block variable not set
---------------------------
OK   Help  
---------------------------

and this

---------------------------
Microsoft Visual Basic
---------------------------
Object variable or With block variable not set
---------------------------
OK   Help  
---------------------------

I have the code in this snippet  ID: 23170878
In a call module and thisoutlooksession
When run after selecting a mail i get these error messages
I don't understand what you mean when you say "When run".  That sounds as if you're trying to run some code.  This code runs automatically.
When run i mean.
I select a mail then run the macro to get a notes poped up. Thats what i meant....
But that's a problem.  You don't run anything for the note to pop-up.  It's automatic.  If you're running something, then that's the problem.
Even to enter.
What i mean is .
I first click on a mail and then run macro to get the notes box. After which i type some data in the notes and close. Then when ever i open the email the notes has to popup....
Is that right
Even to enter.
What i mean is .
I first click on a mail and then run macro to get the notes box. After which i type some data in the notes and close. Then when ever i open the email the notes has to popup....
Is that right
Yes, that's correct.  
Now when i select a mail and run the macro
I get this

---------------------------
Microsoft Visual Basic
---------------------------
Object variable or With block variable not set
---------------------------
OK   Help  
---------------------------

I dont even get the notes now.
Is there any Reference that i need to add?
Now when i select a mail and run the macro
I get this

---------------------------
Microsoft Visual Basic
---------------------------
Object variable or With block variable not set
---------------------------
OK   Help  
---------------------------

I dont even get the notes now.
Is there any Reference that i need to add?
Where?  What line?  I can't determine what's happening just by an error message.  I have to know where the error occurs.
No, there are no references to add.  I would have told you to add them if there were.  The code as I posted it initially works perfectly as is.  Something is wrong at your end.  There is either some other code that's interfering with this, something that's killing this code, or the instructions I gave haven't been followed.
When i select the mail and run the macro i get this error.
So i cannot find the link its giving me the error.
Ok shall delete all the code  in my machine and try...
When i select the mail and run the macro i get this error.
So i cannot find the link its giving me the error.
Ok shall delete all the code  in my machine and try...
I just removed all the modules and codes in my outlook and have placed just this code.

Attached is the screenshot.

Still dont get the notes popup when i open the mail

I commented these 2 lines as before and when ran
I get this error it does not show any line where it gets the error.

---------------------------
Microsoft Visual Basic
---------------------------
Object variable or With block variable not set
---------------------------
OK   Help  
---------------------------

I commented these 2 lines

'On Error Resume Next
    Set olkMsg = Application.ActiveInspector.CurrentItem
    If olkMsg.Class = olMail Then
        Set olkNote = olkNotesFolder.Items.Add()
        olkNote.Body = "Linked to: " & olkMsg.Subject
        olkNote.Save
        Set olkProp = olkMsg.UserProperties.Add("LinkedNote", olText)
        olkProp.Item("LinkedNote").Value = olkNote.EntryID
        olkMsg.Save
        olkNote.Display
    End If
    Set olkProp = Nothing
    Set olkNote = Nothing
    Set olkMsg = Nothing
    'On Error GoTo 0

Please help troubleshoot as i dont want to miss this excellent code. Which would be very useful for me...

ScreenShot026.jpg
Ok, let's see if we can fix this.

1.  Replace the code in the class module with the version below.
2.  Close and restart Outlook
3.  Open the VB editor window (ALT+F11)
4.  Look in the Immediate window at the bottom of the screen.  If you don't see the window, then click View > Immediate Window
5.  Minimize the VB editor
6.  Try to add a note to a message
7.  Close and reopen the message
8.  Go back to the VB editor window
9.  Copy the contents of the Immediate window and post it here for me to look at
Option Explicit
 
'*** Constants
Const CLASSNAME = "Linked Note Manager"
Const VERSION = "v1.0"
 
'*** 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("Linked Notes")
    If TypeName(olkNotesFolder) = "Nothing" Then
        Set olkNotesFolder = Session.GetDefaultFolder(olFolderNotes)
        Set olkNotesFolder = olkNotesFolder.Folders.Add("Linked Notes", olFolderNotes)
    End If
    Set olkApp = Application
    Set olkInspectors = olkApp.Inspectors
    Debug.Print "Class Initialized"
    On Error GoTo 0
End Sub
 
Private Sub Class_Terminate()
    Set olkApp = Nothing
    Set olkInspectors = Nothing
    Set olkInspector = Nothing
    Set olkNotesFolder = Nothing
    Debug.Print "Class Terminated"
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
        Debug.Print "Message Window Opened"
        Set olkMsg = Inspector.CurrentItem
        Set olkProp = olkMsg.UserProperties.Find("LinkedNote", True)
        Debug.Print "Property: " & TypeName(olkProp)
        If TypeName(olkProp) = "UserProperty" Then
            Set olkNote = Session.GetItemFromID(olkProp.Value)
            If TypeName(olkNote) <> "Nothing" Then
                olkNote.Display
            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
 
Public Sub AddNoteToMsg()
    Dim olkMsg As Object, _
        olkNote As Outlook.NoteItem, _
        olkProp As Outlook.UserProperty
    On Error Resume Next
    Set olkMsg = Application.ActiveInspector.CurrentItem
    If olkMsg.Class = olMail Then
        Debug.Print "Adding Note"
        Set olkNote = olkNotesFolder.Items.Add()
        olkNote.Body = "Linked to: " & olkMsg.Subject
        olkNote.Save
        Set olkProp = olkMsg.UserProperties.Add("LinkedNote", olText)
        olkProp.Item("LinkedNote").Value = olkNote.EntryID
        olkMsg.Save
        olkNote.Display
    End If
    Set olkProp = Nothing
    Set olkNote = Nothing
    Set olkMsg = Nothing
    On Error GoTo 0
End Sub

Open in new window

I get this in the intermediate window...

Class Initialized
Adding Note
Message Window Opened
Property: Nothing
Message Window Opened
Property: Nothing
Adding Note
Message Window Opened
Property: Nothing
I get this in the intermediate window...

Class Initialized
Adding Note
Message Window Opened
Property: Nothing
Message Window Opened
Property: Nothing
Adding Note
Message Window Opened
Property: Nothing
Did the note add ok?  Does it appear in the Linked Notes folder?  
Replace the code in the class module with the code below.  Close and restart Outlook.  Open an item and add a note.  Close and re-open the same message.  Does the note appear (rememebr, it will probably appear behind the message)?
Option Explicit
 
'*** Constants
Const CLASSNAME = "Linked Note Manager"
Const VERSION = "v1.0"
 
'*** 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("Linked Notes")
    If TypeName(olkNotesFolder) = "Nothing" Then
        Set olkNotesFolder = Session.GetDefaultFolder(olFolderNotes)
        Set olkNotesFolder = olkNotesFolder.Folders.Add("Linked Notes", 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 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("LinkedNote", True)
        If TypeName(olkProp) = "UserProperty" Then
            Set olkNote = Session.GetItemFromID(olkProp.Value)
            If TypeName(olkNote) <> "Nothing" Then
                olkNote.Display
            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
 
Public Sub AddNoteToMsg()
    Dim olkMsg As Object, _
        olkNote As Outlook.NoteItem, _
        olkProp As Outlook.UserProperty
    On Error Resume Next
    Set olkMsg = Application.ActiveInspector.CurrentItem
    If olkMsg.Class = olMail Then
        Set olkNote = olkNotesFolder.Items.Add()
        olkNote.Body = "Linked to: " & olkMsg.Subject
        olkNote.Save
        Set olkProp = olkMsg.UserProperties.Add("LinkedNote", 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

Open in new window

Works perfect now...  Thanks a lot.....

Can this work if i run the macro even when i have not totally expanded the message on the screen.

Now. I first have to open the mail then go back to the macro and run. and close the notes. Then when open it comes in the background of the opened mail.

What i ask is.
Can we create a notes even when a mail is not opened rather click on the mail in the pane and run macro. So i get the notes poped?
Works perfect now...  Thanks a lot.....

Can this work if i run the macro even when i have not totally expanded the message on the screen.

Now. I first have to open the mail then go back to the macro and run. and close the notes. Then when open it comes in the background of the opened mail.

What i ask is.
Can we create a notes even when a mail is not opened rather click on the mail in the pane and run macro. So i get the notes poped?
"Can we create a notes even when a mail is not opened rather click on the mail in the pane and run macro. So i get the notes poped?"

Assuming that you mean you want to create the note without having to open the item, then "yes".  

1.  Open the VB editor and go to the class module.
2.  Scroll down to the bottom of the class module and replace Public Sub AddNoteToMsg with the version below.
3.  Close and restart Outlook.

You should not be able to add a note to a message without having to open it.  You will still have to open the message to see an attached note.
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
        Debug.Print "Adding Note"
        Set olkNote = olkNotesFolder.Items.Add()
        olkNote.Body = "Linked to: " & olkMsg.Subject
        olkNote.Save
        Set olkProp = olkMsg.UserProperties.Add("LinkedNote", olText)
        olkProp.Item("LinkedNote").Value = olkNote.EntryID
        olkMsg.Save
        olkNote.Display
    End If
    Set olkProp = Nothing
    Set olkNote = Nothing
    Set olkMsg = Nothing
    On Error GoTo 0
End Sub

Open in new window

Thanks this works but when i open it shows this box
\
---------------------------
Linked Note Manager
---------------------------
The note linked to this item could not be found.
---------------------------
OK  
---------------------------

I can see they are created in the linked notes folder.
Each time i open the mail for which i created the notes i get that box
Thanks this works but when i open it shows this box
\
---------------------------
Linked Note Manager
---------------------------
The note linked to this item could not be found.
---------------------------
OK  
---------------------------

I can see they are created in the linked notes folder.
Each time i open the mail for which i created the notes i get that box
ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect works exact as expected...

Now Q... Now when i dont want the notes any more. As i have completed the task.
I tried deleting the notes from linked folder but when i open a message.i get the message as cannot find. Now how do i stop getting that message after the notes is deleted.

Please let me know if this is going to take a lot of time of yours. Shall post a new Q for this...
Perfect works exact as expected...

Now Q... Now when i dont want the notes any more. As i have completed the task.
I tried deleting the notes from linked folder but when i open a message.i get the message as cannot find. Now how do i stop getting that message after the notes is deleted.

Please let me know if this is going to take a lot of time of yours. Shall post a new Q for this...