Outlook hyperlink context menu

前端 未结 2 1539
夕颜
夕颜 2021-01-28 10:30

I\'m trying to make a context menu for a hyperlink. It seems there are several contexts where hyperlink events can be intercepted -- at the moment I\'m interested in the contex

2条回答
  •  庸人自扰
    2021-01-28 11:15

    I had a similar problem and my solution looked like:

    public void OnCustomHyperlinkMenuClick(IRibbonControl control)
    {
        Explorer explorer = control.Context as Explorer;
        if (explorer != null)
        {
            Document document = explorer.ActiveInlineResponseWordEditor;
            //Note from asker: above line throws a COM Exception ("The operation failed")
    
            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];
                    string hyperlinkUrl = hyperlink.Address;
                    DoSomethingWithUrl(hyperlinkUrl);
                }
            }
        }
    }
    

    You will need to add a reference to the word interop assembly "Microsoft.Office.Interop.Word.dll" to your project.

提交回复
热议问题