0

I have an Outlook add-in, which transform plain text reference numbers (ticket numbers) to clickable hyperlinks. When clicked, they open up the default browsers (as you would except). That works just fine, but now I want to intercept this click, to run c# code of my add-in instead. Similar to how Outlook intercepts clicks on mailto-links to known addresses (it shows the contact card instead).

How can I achieve that?

Jack Frost
  • 5
  • 1
  • 3

1 Answers1

0

The Word Object Model does not have any events that fire when a user clicks on links (Word renders HTML messages in Outlook). The best you can is create your own url handler (e.g. MyHandler:somelink). You can then replace the links in the HTML body.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • I'm familiar with setting custom URI scheme for external applications, but I don't know how I would register a URI scheme for an Outlook add-in. – Jack Frost Dec 22 '19 at 18:18
  • Outlook uses whatever is registered. If you register MyHandler as a url scheme, that is what Outlook will use. – Dmitry Streblechenko Dec 23 '19 at 01:18
  • Correct me if I'm wrong, but as far as I know, the only way to register a url scheme is via win registry, which includes setting a location for the application that handles the url. I can't just set the location of my add-in, since it's not a executable. – Jack Frost Dec 24 '19 at 09:10
  • Correct. And that exe can do whatever you want it to do, including communicate with your addin. – Dmitry Streblechenko Dec 24 '19 at 14:59
  • @JackFrost i'm not sure you understand what Dmitry was suggesting. he suggests you register a protocol. similiar to how `http://` activates default browser and `mailto:` activates default mail handler and `utorrent` and `itunes` do the same. you can read more about it [here](https://stackoverflow.com/questions/796748/how-can-i-add-a-custom-url-handler-on-windows-like-itunes-itms) – Stavm Dec 25 '19 at 12:35
  • I understand what he means. It's called a URL scheme. I just didn't want to deploy an executable with my add-in. I want my add-in to host the code. But I can see that this is just a constraint on my side and that in other cases that wouldn't be a problem. I edited the question again and marked this as the answer. It just doesn't help me. – Jack Frost Dec 25 '19 at 12:43
  • You can specify rundll32.exe as the handler and pass your dll name as one of the parameters if you don't want a separate executable. – Dmitry Streblechenko Dec 27 '19 at 19:55