laiakini
laiakini

Reputation: 31

how to detect which href is clicked in word document using C# VSTO

i have this vsto code where when i click a button some links are pasted

 Microsoft.Office.Interop.Word.Application objApplication = Globals.ThisAddIn.Application;
Microsoft.Office.Interop.Word.Selection objSelection = objApplication.Selection;
Microsoft.Office.Interop.Word.Paragraphs p = objSelection.Paragraphs;
Microsoft.Office.Interop.Word.Range objRange = objSelection.Range;
Microsoft.Office.Interop.Word.Hyperlink hp = (Microsoft.Office.Interop.Word.Hyperlink)objRange.Hyperlinks.Add(objRange, "1");

enter image description here

is there a way i can detect which link has been clicked maybe like show a message box when the link is clicked with its href

Upvotes: 0

Views: 108

Answers (1)

kunz
kunz

Reputation: 1047

maybe you can insert a button and give it some type of uniqueness

      private void button2_Click(object sender, RibbonControlEventArgs e)
        {
            Microsoft.Office.Tools.Word.Controls.Button salesButton;
            Document vstodoc = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveDocument);
            Microsoft.Office.Interop.Word.Application objApplication = Globals.ThisAddIn.Application;
            Microsoft.Office.Interop.Word.Selection objSelection = objApplication.Selection;
            Microsoft.Office.Interop.Word.Range objRange = objSelection.Range;
            salesButton = vstodoc.Controls.AddButton(objRange, 20, 20, "salesButton");
            salesButton.Text = "Calculate Total Sales";
        }
    

Upvotes: 1

Related Questions