How to Effectively Add Notes to Outlook Emails via VBA & UserForm

At times, you may hope to edit or add notes to you emails in Outlook. This article will introduce you an effective way to achieve this function.

From “4 Easy Methods to Insert a Note into Your Outlook Messages“, you can learn to insert notes into mails via Outlook native functions, such as using custom flags, typing note in subject or body, or attaching existing note items to this email. Yet, all of them are just workarounds. Here, we’ll teach you a much more effective method. Via it, you will be able to add notes to emails and edit or delete existing notes at will.

Effectively Add Notes to Outlook Emails via VBA & UserForm

Add Notes to Outlook Emails

  1. To begin with, access VBA editor by pressing “Alt + F11” in Outlook.
  2. Then, click “Insert” > “UserForm”.Insert UserForm
  3. Next, in the new UserForm, create a textbox like the image below.Insert TextBox in UserForm
  4. Then, change the “Name” of the textbox to “txtNotes”, like the screenshot.Change TextBox Name
  5. After that, create two commandbuttons in the form.Create CommandButton
  6. Then, select “CommandButton 1”. Change its “Name” to “btnOK” and alter its “Caption” to “OK”.Change Button Name & Caption
  7. Afterwards, alter the “Name” of “CommandVutton 2” to “btnCancel” and the “Caption” to “Cancel”.
  8. Next, select the entire UserForm and modify its “Name” to “frmAddNote” and “Caption” to “Enter your note”.Change UserForm Name & Caption
  9. Subsequently, right click the “fromAddNote” and choose “View Code”.View Code of "frmAddNote"
  10. In the new screen, copy the following code into it.
Private Sub btnOK_Click()
    Dim strNote As String
    Dim objMail As Outlook.MailItem
    Dim objNote As Outlook.NoteItem
 
    strNote = txtNotes.Text
 
    Set objMail = Application.ActiveExplorer.Selection.Item(1)
    Set objNote = Application.CreateItem(olNoteItem)
 
    objNote.Body = strNote
    objNote.Save
    objMail.Attachments.Add objNote
    objMail.Save
    objNote.Delete
    Unload Me
End Sub

Private Sub btnCancel_Click()
    Unload Me
End Sub

"frmAddNote" Code

  1. Later, put the VBA code below into an unused module.
Sub AddNote()
    frmAddNote.Show
End Sub

Show "frmAddNote"

  1. Finally, head to “File” > “Options” > “Customize Ribbon” to add this macro to ribbon.Add "AddNote" Macro to Ribbon
  2. Now, you can have a try. Select an email and click the new “Add Note” button in ribbon.Add Note to Selected Email
  3. In the popup dialog box, you can enter you note and click “OK”.Enter your note in box
  4. Immediately, a new note will be added to the selected email.Added Note

Edit or Delete Existing Notes for Outlook Emails

At times, you may want to edit or delete any existing notes in an email. You can follow the steps below.

  1. First off, create another userform and name it as “frmEditNote” and modify its caption to “Edit your note”.Create a UseForm Called "frmEditNote"
  2. Then, insert a new textbox in the form and change its “Name” to “txtNotes”.
  3. Next, add two commandbuttons – “OK” and “Cancel”.
  4. After that, right click “frmEditNote” and select “View Code”.
  5. In the new code page of “frmEditNote”, put the following code.
Private Sub UserForm_Initialize()
    Dim objAttachNote As Outlook.Attachment
    Dim objTempNote As Outlook.NoteItem

    Set objAttachNote = ActiveExplorer.AttachmentSelection.Item(1)
    Set objMail = objAttachNote.Parent
 
    If Right(objAttachNote.FileName, 3) = "msg" Then
       strTempFolder = Environ("Temp")
       strFilePath = strTempFolder & "\" & objAttachNote.FileName
       objAttachNote.SaveAsFile strFilePath
    End If
 
    Set objTempNote = Session.OpenSharedItem(strFilePath)
    txtNotes.Text = objTempNote.Body

    objTempNote.Close olDiscard
End Sub

Private Sub btnOK_Click()
    Dim strNote As String
    Dim objMail As Outlook.MailItem
    Dim objAttachNote As Outlook.Attachment
    Dim objNewNote As Outlook.NoteItem
 
    strNote = txtNotes.Text
 
    Set objNewNote = Application.CreateItem(olNoteItem)
    Set objMail = Application.ActiveExplorer.Selection.Item(1)
    Set objAttachNote = ActiveExplorer.AttachmentSelection.Item(1)
    objAttachNote.Delete

    objNewNote.Body = strNote
    objNewNote.Save
    objMail.Attachments.Add objNewNote
    objMail.Save
    objNewNote.Delete
    Unload Me
End Sub

Private Sub btnCancel_Click()
    Unload Me
End Sub

"frmEditNote" Code

  1. After that, open a module and copy the VBA code into it.
Sub EditNote()
    frmEditNote.Show
End Sub

Sub DeleteNotes()
    Dim objSelectedAttachments As Outlook.AttachmentSelection
    Dim objAttachment As Outlook.Attachment
    Dim objMail As Outlook.MailItem
 
    Set objSelectedAttachments = Application.ActiveExplorer.AttachmentSelection
 
    For Each objAttachment In objSelectedAttachments
        If Right(objAttachment.FileName, 3) = "msg" Then
           objAttachment.Delete
        End If
    Next
 
    Set objMail = Application.ActiveExplorer.Selection.Item(1)
    objMail.Save
End Sub

Add "Edit Note" Code & "Delete Notes" Code

  1. Finally, you can add the “EditNote” and “DeleteNotes” macros to ribbon.Add "EditNote" & "DeleteNotes" Macro to Ribbon
  2. Lastly, after click “OK” and return to the main window, you can try to edit a note.
  • Select a note and click the “Edit Note” button.Edit Note
  • Then, a new dialog box will show up, in which you can edit the selected note.Change Note in Dialog Box
  • After editing, click “OK”. The note will be updated.Updated Note
  1. Also, you can try to delete any notes.
  • Select the note you want to delete.
  • Click the “Delete Notes” button in ribbon.Delete Note
  • This note will be deleted at once.Note Disappear

Prevent Outlook from Data Loss

Are you searching a mighty solution to block Outlook data loss? In honesty, as long as you make regular Outlook data backups, you can avoid PST data loss with ease. For instance, even if PST gets damaged, you still can easily recover PST data from the backed up PST file like a breeze.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including recover sql and outlook repair software products. For more information visit www.datanumen.com

Comments are closed.