none
how to add a new option to context menu of hyperlink in an email for Outlook 2010? RRS feed

  • Question

  • I see Outlook 2010 provides a lot of things you can customize epsecially in terms of UI.

    However, I did not find any document on how to customize context menu of hyperlinks in an email?

    Specifically, I would like to add a menu item to open the link in a non-default brower. Now you select, copy, open (in the system wide default) the link in a browser.

    Thanks,

    Friday, February 10, 2012 7:25 PM

Answers

  • I don't see anything in the list of menu id's for that. As far as I can tell that context menu can't be customized.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Guangming" <=?utf-8?B?R3VhbmdtaW5n?=> wrote in message news:5cbb4960-0666-4454-aff6-5f654e10ade0...

    I did look at the link before, which just talked how to customize context menu of a lot of items, eg mail, task, calendar, ....

    However it did not mention the context menu of hyperlink in an email.

    Hope I am clear enough here!


    Ken Slovak MVP - Outlook
    • Marked as answer by Guangming Tuesday, February 14, 2012 4:58 PM
    Monday, February 13, 2012 2:45 PM

All replies

  • See http://archive.msdn.microsoft.com/odcOL14ExtendingUI for how to extend the Outlook 2010 user interface, including context menus.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Guangming" <=?utf-8?B?R3VhbmdtaW5n?=> wrote in message news:8c004bb1-398f-44be-bcde-a54ec523ee69...

    I see Outlook 2010 provides a lot of things you can customize epsecially in terms of UI.

    However, I did not find any document on how to customize context menu of hyperlinks in an email?

    Specifically, I would like to add a menu item to open the link in a non-default brower. Now you select, copy, open (in the system wide default) the link in a browser.

    Thanks,


    Ken Slovak MVP - Outlook
    Friday, February 10, 2012 8:36 PM
  • I did look at the link before, which just talked how to customize context menu of a lot of items, eg mail, task, calendar, ....

    However it did not mention the context menu of hyperlink in an email.

    Hope I am clear enough here!

    Friday, February 10, 2012 9:53 PM
  • I don't see anything in the list of menu id's for that. As far as I can tell that context menu can't be customized.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Guangming" <=?utf-8?B?R3VhbmdtaW5n?=> wrote in message news:5cbb4960-0666-4454-aff6-5f654e10ade0...

    I did look at the link before, which just talked how to customize context menu of a lot of items, eg mail, task, calendar, ....

    However it did not mention the context menu of hyperlink in an email.

    Hope I am clear enough here!


    Ken Slovak MVP - Outlook
    • Marked as answer by Guangming Tuesday, February 14, 2012 4:58 PM
    Monday, February 13, 2012 2:45 PM
  • Hello,

    Pay attention that the Office 2010 Context Menus add-in does add an item to that context menu! That is, there's a way to customize that context menu.


    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    Tuesday, February 14, 2012 5:11 PM
  • wow, this is revolutionary! I will try itn now!
    Wednesday, February 15, 2012 2:40 PM
  • That add-in does work! the id is ContextMenuReadOnlyMailHyperlink, so what is the next to add my own link to replace that?

    Seems there is no document on how that master/generic add-in was created!

    Some recommendation?

    Wednesday, February 15, 2012 2:52 PM
  • Hello,

    That add-in customizes the Ribbon UI in a usual way. ContextMenuReadOnlyMailHyperlink and ContextMenuHyperlink are IdMso values specified in Word. You cannot replace that context menu. But you can add an item to it. As you can see.


    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    Wednesday, February 15, 2012 3:03 PM
  • I did add a new menuitem to that hyperlink context menu. Now I need to find the hyperlink I right-clicked.

    What I got is the whole email item from Office.IRibbonControl.Context, which is an Outlook.Explorer with one Selection. The selection turns out to be an OutlookItem.

    It does have an email body. But I may have multiple hyperlinks in inside it. It must be a way to get the hyperlink because other menu items work: Open, Select, Copy Hyperlink.

    Any ideas?


    • Edited by Guangming Wednesday, February 15, 2012 8:03 PM
    Wednesday, February 15, 2012 7:36 PM
  • Hello,

    Any success with getting this to work? We are attempting to produce the same.

    Thanks!

    Thursday, December 13, 2012 2:52 AM
  • i guess you would have to use redemption to get access to wordeditor of reading pane, and then use Word API to get selected range which will be your hyperlink.
    Thursday, December 13, 2012 7:54 AM
  • Sorry for late reply. Only just had a chance to look at this. Will give it a try but might be beyond me.
    Thursday, January 31, 2013 5:50 AM
  • Hi,

    I´ve had the same problem and my solution was:

           public void OnCustomHyperlinkMenu(IRibbonControl control)
            {
                Explorer explorer = control.Context as Explorer;
                if (explorer != null)
                {
                    Document document = explorer.ActiveInlineResponseWordEditor;
                    if (document != null && document.Windows != null && document.Windows.Count > 0)
                    {
                        Microsoft.Office.Interop.Word.Selection selection = document.Windows[1].Selection;
                        if (selection != null && selection.Hyperlinks != null && selection.Hyperlinks.Count > 0)
                        {
                            Hyperlink hyperlink = selection.Hyperlinks[1];
                            DoSomethingWithUrl(hyperlink.Address);
                        }
                    }
                }
            }

    Best regards,

    Thomas

    Saturday, February 22, 2014 12:44 PM
  • Hi Thomas,

    Great news!

    Can you provide me some more detail into your solution? Will this produce an extra menu item when you click on a hyperlink within an Outlook email?

    Thanks!

    Monday, February 24, 2014 6:19 AM
  • Hi @Guangming

    How did you add a new item to the context menu in the email body?

    Thursday, September 3, 2015 10:42 AM
  •  http://archive.msdn.microsoft.com/odcOL14ExtendingUI tells you how to customize the ribbon interface, and Andrei provided the id's you need to customize the hyperlink context menu. Thomas provided code to handle finding which hyperlink was clicked.

    What else do you need?


    Ken Slovak MVP - Outlook

    Thursday, September 3, 2015 1:37 PM
  • Is anyone still monitoring this thread? I am having trouble with Thomas' code. I have used the above function as the onAction of my contextMenu button, but I do not get the expected results.

    I am getting the following exception when trying to set document = to explorer.ActiveInlineResponseWordEditor

    System.Runtime.InteropServices.COMException occurred
      HResult=0x88304002
      Message=The operation failed.
      Source=Microsoft Outlook
      StackTrace:
       at Microsoft.Office.Interop.Outlook._Explorer.get_ActiveInlineResponseWordEditor()
       at UploadPMReports.Ribbon2.OnCustomHyperlinkMenu(IRibbonControl control) in C:\Users\samuel.ryan\source\repos\UploadPMReports\UploadPMReports\Ribbon2.cs:line 76

    Can anyone help me further with this. I have the context menu displaying properly I just want to actually be able to get the hyperlink info so that I can do something with it.

    Thursday, February 22, 2018 6:52 PM
  • Use IRibbonControl.Context to get the window in which the context menu is shown. I suppose that window is Inspector in your case. Use Inspector.WordEditor to get the document.

    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    Friday, February 23, 2018 6:44 AM
  • I am able to get the inspector as you outlined above as long as I open the email first, but I am trying to figure out how to get the inspector when I am right clicking in the reading view pane. Thomas and others seem to be saying that that would be an explorer object and you could get the text with an ActiveInlineResponseWordEditor() but this isn't working.

    I have attached the code below with what works and what doesn't. Thank you for your consideration.

    public void OnCustomHyperlinkMenu(Office.IRibbonControl control)
            {
               
                if (control.Context is Inspector inspector) //This works
                {

                    Document document = inspector.WordEditor;


                    MessageBox.Show(document.ToString());
                    if (document != null && document.Windows != null && document.Windows.Count > 0)
                    {
                        MessageBox.Show("Check-2");
                        Microsoft.Office.Interop.Word.Selection selection = document.Windows[1].Selection;
                        if (selection != null && selection.Hyperlinks != null && selection.Hyperlinks.Count > 0)
                        {
                            MessageBox.Show("Check-3");
                            Hyperlink hyperlink = selection.Hyperlinks[1];
                            MessageBox.Show(hyperlink.TextToDisplay);
                            //var success = FileDownloader.DownloadFile(hyperlink.Address, "C:\\temp\\myfile.pdf", 10000);
                        }
                    }
                }
                else if (control.Context is Explorer explorer) // This works
                {

                    Document document = explorer.ActiveInlineResponseWordEditor; //this doesn't work.
                    

                }
            }

    Monday, February 26, 2018 8:13 PM
  • I see. This looks like an issue in Outlook. What Office build are you using? Try to update Office. If this doesn't help, start a System.Windows.Forms.Timer; I suppose any small value will do. When the timer's event is triggered get ActiveInlineResponse. Does it work this way?

    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    Tuesday, February 27, 2018 9:23 PM
  • I'm using Outlook 2016. From everything I have read Thomas' code should work.

    The WordEditor of an Inspector Object should be equal to the ActiveInlineResponseWordEditor of an Explorer Object, but this is not the case. I was finally able to get the text of the email body that is being viewed in the reading pane using the following:                                   

     Document document = explorer.Selection[1].GetInspector().WordEditor;

                    if (document != null && document.Windows != null && document.Windows.Count > 0)
                    {

                        Microsoft.Office.Interop.Word.Selection selection = document.Windows[1].Selection;
                        MessageBox.Show(selection.Text);

    But, the selection that was returned ends up just being the first character of the email being displayed. I Don't know if this is just my lack of understanding on the Outlook object model, or is this is an error.

    Wednesday, February 28, 2018 8:28 PM
  • This is a problem for me too. I can get the link from the inspector when the email is open but not from the reading pane.

    Did you ever find a solution?

    Tuesday, July 31, 2018 1:23 PM