OutlookLink - butscher/WikidPad GitHub Wiki

This VBA macro code is heavily inspired by the information available at [http://mutable.net/blog/archive/2006/09/02/how_to_hyperlink_to_microsoft_outlook_messages.aspx]. I only adjusted the generated link text to make it suitable for use in WikidPad.

Just create these macros in Outlook, and optionally bind the macro to a toolbar button or menu command for easy access.

In Outlook, select one or more messages and execute the macro (using the toolbar button, for example). Your clipboard will now contain direct URL links to these messages in a WikidPad-ready format, ready to be pasted in your wiki page. By default, the link shows the message subject, author and received date & time. This can be adjusted in the GetMsgDetails() function if needed.

Note

For Outlook 2007, these links won't work out-of-the-box. That's because Outlook 2007 does not register the "outlook:" protocol handler in Windows. You can configure this yourself using RegEdit, a detailed explanation is available over here: [http://www.slipstick.com/outlook/ol2007/outlookprotocol.asp]. Outlook links in WikidPad should work without problems afterwards.

The code

Sub CopyItemIDs()
    Dim myOLApp As Application
    Dim myNameSpace As NameSpace
    Dim currentMessage As MailItem
    Dim ClipBoard As String
    Dim DataO As DataObject
    
    ' Housekeeping: set up the macro environment
    Set myOLApp = CreateObject("Outlook.Application")
    Set myNameSpace = myOLApp.GetNamespace("MAPI")
    
    ' Figure out if the active window is a list of messages or one message
    ' in its own window
    On Error GoTo QuitIfError    ' But if there's a problem, skip it
    Select Case myOLApp.ActiveWindow.Class
        ' The active window is a list of messages (folder); this means there
        ' might be several selected messages
        Case olExplorer
            ' build the clipboard string
            For Each currentMessage In myOLApp.ActiveExplorer.Selection
                ClipBoard = GetMsgDetails(currentMessage, ClipBoard)
            Next
             
        ' The active window is a message window, meaning there will only
        ' be one selected message (the one in this window)
        Case olInspector
            ' build the clipboard string
            ClipBoard = GetMsgDetails(myOLApp.ActiveInspector.CurrentItem, _
                                         ClipBoard)
        ' can't handle any other kind of window; anything else will be ignored
    End Select
    
QuitIfError:       ' Come here if there was some kind of problem
    Set myOLApp = Nothing
    Set myNameSpace = Nothing
    Set currentMessage = Nothing

    Set DataO = New DataObject
    DataO.Clear
    DataO.SetText ClipBoard
    DataO.PutInClipboard
    
    Set DataO = Nothing
End Sub
Function GetMsgDetails(Item As MailItem, Details As String) As String

    If Details <> "" Then
        Details = Details + vbCrLf
    End If
    Details = Details + "[Outlook:" + Item.EntryID + " | " + Item.Subject + " (" + Item.SenderName + ", " + Format(Item.ReceivedTime, "yyyymmdd | hh:mm") + ")]" + vbCrLf
    GetMsgDetails = Details

End Function
⚠️ **GitHub.com Fallback** ⚠️