I wrote a simple VSTO addon that inserts a hyperlink into an email message when a user clicks the feed button. Here is a sample code:
private void button1_Click(object sender, RibbonControlEventArgs e) { var context = e.Control.Context as Inspector; if (context != null) { if (context.IsWordMail()) { var doc = context.WordEditor as Document; if (doc != null) { var sel = doc.Windows[1].Selection; doc.Hyperlinks.Add(sel.Range, "http://www.google.com", "", "", "Google", ""); } } } else if (e.Control.Context is Explorer) { Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer(); if (explorer.Selection.Count == 1) { Microsoft.Office.Interop.Outlook.Selection itemSelection = explorer.Selection; var item = itemSelection[1] as MailItem;
This works well when the email is edited in separate windows ( e.Control.Context is Inspector ).
If the messsage message is answered / forwarded and the reading pane is turned on, the editor is displayed inside the reading line ( e.Control.Context is Explorer ).
I cannot figure out how to get the Document instance in this case. I can access the item selected in Explorer, but I cannot figure out how to access the document editor displayed in the reading pane.
If I βpulledβ the editor into a separate window, it works fine (context changes in Inspector).
Is there a way to access an email document that is being edited directly inside the reading area?
With a lot of help from Dmitry , who pointed me in the right direction, I found that in the Explorer class there is a property: Explorer.ActiveInlineResponseWordEditor , which gives you the editor displayed in a row.
source share