Skip to content

Instantly share code, notes, and snippets.

@taglia
Last active May 3, 2016 15:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taglia/5993780 to your computer and use it in GitHub Desktop.
Save taglia/5993780 to your computer and use it in GitHub Desktop.
See the README below for more details. This gist is linked from this blog post: http://www.osomac.com/2013/07/14/farewell-omnifocus-welcome-org-mode-pt-2/

This gist contains two VBA macros:

  • AddLinkToMessageInClipboard: Moves a message to an archive folder, then generates a link to the message ready to be pasted in org-mode. I am moving the message to the archive first because Outlook changes the message ID's when it is moved to a different storage;
  • AddLinkToOpenMessageInClipboard: Grabs the link to an open message, without moving it.

And an elisp snippet to tell Emacs how to open the Outlook links: org-outlook.el. You can copy this snippet to your .emacs file

Credit to this post on superuser.com for the initial idea.

Disclaimers

  • I have close-to-zero knowledge of VB and VBA, apologies if I used any anti-patterns or bad practices;
  • I use this every day on Outlook 2003 and Emacs 24, not tested on any other versions.
'Move the selected message to an archive folder,
'Then Adds an org-mode friendly link to the message to the clipboard
Sub AddLinkToMessageInClipboard()
Dim objMail As Outlook.MailItem
Dim doClipboard As New DataObject
Dim destFolder As Outlook.MAPIFolder
Dim nameSpace As Outlook.nameSpace
Dim inBox As Outlook.MAPIFolder
Dim app As New Outlook.Application
Dim objMailAfterMove As Outlook.MailItem
'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 nameSpace = app.GetNamespace("MAPI")
Set inBox = nameSpace.GetDefaultFolder(olFolderInbox)
'Set the destination folder HERE
Set destFolder = nameSpace.Folders("Archive")
Set objMail = Application.ActiveExplorer.Selection.Item(1)
Set objMailAfterMove = objMail.Move(destFolder)
doClipboard.SetText "[[outlook:" + objMailAfterMove.EntryID + "][MESSAGE: " + objMail.Subject + " (" + objMail.SenderName + ")]]"
doClipboard.PutInClipboard
End Sub
'Move the open message to the archive folder,
'Then Adds a link to the message to the clipboard
Sub AddLinkToOpenMessageInClipboard()
Dim objMail As Outlook.MailItem
Dim doClipboard As New DataObject
Set objMail = Application.ActiveWindow.CurrentItem
doClipboard.SetText "[[outlook:" + objMail.EntryID + "][MESSAGE: " + objMail.Subject + " (" + objMail.SenderName + ")]]"
doClipboard.PutInClipboard
End Sub
;;; org-outlook.el - Support for links to Outlook items in Org
(require 'org)
(org-add-link-type "outlook" 'org-outlook-open)
(defun org-outlook-open (id)
"Open the Outlook item identified by ID. ID should be an Outlook GUID."
(w32-shell-execute "open" (concat "outlook:" id)))
(provide 'org-outlook)
;;; org-outlook.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment