How to handle outlook links in obsidian (messages, contacts, appointments...)

At work, I have lots of emails, appointments, and contacts I would like to save or reference in Obsidian. Linking a person in obsidian with the contact you have in outlook is quite useful but creating those kinds of links for obsidian is a bit problematic. I find out a walkaround that works for me.

There are several problems:

  1. Since Office 2007 “Outlook:” links don’t work.
  2. Even if they work, you have to reference an individual item and you don’t know the id.
  3. It has to be easy to do, like pressing a button. :grin:
  • For the first problem, you need to modify the registry. Here you have a link with not only the modifications but also some files to do it automatically.
  • When it comes to the second point, I come out with some code to be implemented as a macro in Outlook (thanks to link):

Function SetClipBoardText(ByVal Text As Variant) As Boolean
SetClipBoardText = CreateObject(“htmlfile”).ParentWindow.ClipboardData.SetData(“Text”, Text)
End Function

'Adds a link to the currently selected message to the clipboard
Sub ObsidianLink()

Dim objMail As Object
Dim txtObsLink As String
Dim exito As Boolean

’ Dim doClipboard As New 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)

If objMail.Class = olMail Then
txtObsLink = “[MESSAGE: " + objMail.Subject + " (” + objMail.SenderName + “)](outlook:” + objMail.EntryID + “)”

ElseIf objMail.Class = olAppointment Then
    txtObsLink = "[MEETING: " + objMail.Subject + " (" + objMail.Organizer + ")](outlook:" + objMail.EntryID + ")"
ElseIf objMail.Class = olTask Then
    txtObsLink = "[TASK: " + objMail.Subject + " (" + objMail.Owner + ")](outlook:" + objMail.EntryID + ")"
ElseIf objMail.Class = olContact Then
    txtObsLink = "[CONTACT: " + objMail.Subject + " (" + objMail.FullName + ")](outlook:" + objMail.EntryID + ")"
ElseIf objMail.Class = olJournal Then
    txtObsLink = "[JOURNAL: " + objMail.Subject + " (" + objMail.Type + ")](outlook:" + objMail.EntryID + ")"
ElseIf objMail.Class = olNote Then
    txtObsLink = "[NOTE: " + objMail.Subject + " (" + " " + ")](outlook:" + objMail.EntryID + ")"
Else
    txtObsLink = "[ITEM: " + objMail.Subject + " (" + objMail.MessageClass + ")](outlook:" + objMail.EntryID + ")"

End If

’ doClipboard.SetText txtObsLink
’ doClipboard.PutInClipboard

exito = SetClipBoardText(txtObsLink)

End Sub

  • For the last point, you just need to create a button with the macro.

In the end, It works like this:
When you find an item (message, appointment, contact…) that you want to reference in Obsidian, you only need to do two things.

  1. Press the button you have programed
  2. Go to obsidian and paste the link

I hope it would be helpful.

David

5 Likes

Thanks a lot David - this worked perfectly!

If anyone runs into any issues with this, note that you may have to adjust some of the " and ’ in your code snippet when copy pasting them into Visual Basic.

2 Likes

Thanks for this @dfeliu! Here is the script with the quotes corrected:

    Function SetClipBoardText(ByVal Text As Variant) As Boolean
SetClipBoardText = CreateObject("htmlfile").ParentWindow.ClipboardData.SetData("Text", Text)
End Function

'Adds a link to the currently selected message to the clipboard
Sub ObsidianLink()

Dim objMail As Object
Dim txtObsLink As String
Dim exito As Boolean

Dim doClipboard As New 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)

If objMail.Class = olMail Then
txtObsLink = "[MESSAGE: " + objMail.Subject + " (" + objMail.SenderName + ")](outlook:" + objMail.EntryID + ")"

ElseIf objMail.Class = olAppointment Then
    txtObsLink = "[MEETING: " + objMail.Subject + " (" + objMail.Organizer + ")](outlook:" + objMail.EntryID + ")"
ElseIf objMail.Class = olTask Then
    txtObsLink = "[TASK: " + objMail.Subject + " (" + objMail.Owner + ")](outlook:" + objMail.EntryID + ")"
ElseIf objMail.Class = olContact Then
    txtObsLink = "[CONTACT: " + objMail.Subject + " (" + objMail.FullName + ")](outlook:" + objMail.EntryID + ")"
ElseIf objMail.Class = olJournal Then
    txtObsLink = "[JOURNAL: " + objMail.Subject + " (" + objMail.Type + ")](outlook:" + objMail.EntryID + ")"
ElseIf objMail.Class = olNote Then
    txtObsLink = "[NOTE: " + objMail.Subject + " (" + " " + ")](outlook:" + objMail.EntryID + ")"
Else
    txtObsLink = "[ITEM: " + objMail.Subject + " (" + objMail.MessageClass + ")](outlook:" + objMail.EntryID + ")"

End If

doClipboard.SetText txtObsLink
doClipboard.PutInClipboard

exito = SetClipBoardText(txtObsLink)

End Sub

Here is how to create a button for the script: How to Create a Custom Outlook Ribbon Button to Cc Yourself Before Sending an Email | Jon Gallant

1 Like

One more step that I needed to do to get this working was this: https://answers.microsoft.com/en-us/msoffice/forum/all/mystery-compile-error-user-defined-type-not/b0c07a65-9f0c-43f1-a181-12c95db0ac8d

A perhaps easier way of getting emails from Outlook to Obsidian is to simply drag them from Outlook to Obsidian. It is then copied as an attachment into Obsidian and can be clicked to be opened.

I was so excited to try this! Got the macro set up, put the Outlook button in place, ran the macro and pasted the link perfectly into Obsidian. Couldn’t believe it all worked so smooth on the first pass.

And then… clicked on the link… and nothing. Created several more outlook links and still none of them would open the outlook object. Now I’m lost. Any suggestions?

Same thing here, @Bobparker did you figure anything out?

Make sure the path to outlook.exe is correct in registry

Yep, that was it. Thanks @arnonel !

Hi,
very nice!!! :slight_smile:
Do you know how to add the date-Information of the Mail into the VBA-Code?

Hi Gnopps,
you seem to know a little bit of VBA. I don’t so, here is my question for a modification of your code:

Do you know how to add the date-Information of the Mail into the VBA-Code?

Thanks in advance,
Silias

Sorry can’t help you. I just took existing scripts and modified them. Furthermore, I am no longer using this script as it doesn’t work if you use the system on another computer or reinstall your Outlook.

Instead I am nowadays simply dragging the email from Outlook to Obsidian.

1 Like