Skip to content

Instantly share code, notes, and snippets.

@program247365
Created February 8, 2011 18:36
Show Gist options
  • Save program247365/816933 to your computer and use it in GitHub Desktop.
Save program247365/816933 to your computer and use it in GitHub Desktop.
VBA Macro for Outlook 2007 that will allow you to get a link for a particular message that is selected. Be sure to go to "Insert" > "UserForm" to be able to get a reference to the clipboard in your project for this to work.
' Code lifted and adjusted from: http://superuser.com/questions/71786/can-i-create-a-link-to-a-specific-email-message-in-outlook
' You may have to enable links in Outlook if these links are destined for Outlook itself - http://www.davidtan.org/outlook-2007-adding-outlook-url-protocol/
' Reference: http://www.davidtan.org/create-hyperlinks-to-outlook-messages-folders-contacts-events/
' To Assign Keyboard Shortcut to your new Macro: http://stackoverflow.com/questions/57075/how-do-i-assign-a-keyboard-shortcut-to-a-vba-macro-in-outlook-2007
'Adds a link to the currently selected message to the clipboard
Sub AddLinkToMessageInClipboard()
Dim objMail As Outlook.MailItem
Dim doClipboard As New MSForms.DataObject
'One and ONLY one message muse be selected
If Application.ActiveExplorer.Selection.Count <> 1 Then
MsgBox ("Select one and ONLY one message.")
Exit Sub
End If
Set objMail = Application.ActiveExplorer.Selection.Item(1)
'doClipboard.SetText "[[outlook:" + objMail.EntryID + "][MESSAGE: " + objMail.Subject + " (" + objMail.SenderName + ")]]"
doClipboard.SetText "<a href='outlook:" + objMail.EntryID + "'>" + objMail.Subject + "'>"
doClipboard.PutInClipboard
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment