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
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.