Get word on right click RRS feed

  • Question

  • Hello,

    I have the following code:

    Word.Selection selection = Globals.ThisAddIn.Application.Selection;
    if (selection != null && !String.IsNullOrEmpty(selection.Text))
       string selectionText = selection.Text;

    This code shows a message box with the selected text when I right-click on it.

    My question is, how can I make it work without having to have the word selected, but still show the word it was clicked on - just like synonyms and definition works.

    Thank you

    Friday, September 5, 2014 11:34 AM


All replies

  • Hello Bruno,

    You may find the required information using the Information property of the Selection class.

    Friday, September 5, 2014 1:34 PM
  • Hello,

    Thank you for your reply, I'm looking at the WdInformation[1] page, but I can't seem to find a member that would make this work.

    Thanks again for your reply.


    I realize my original question might be a bit confusing, so, let's say I have this text:

    This is just an example.

    So if I right click anywhere "inside" the word example, it would show a message box saying example.


    • Edited by Bruno_MM Friday, September 5, 2014 4:26 PM
    Friday, September 5, 2014 3:25 PM
  • 'Selection' property is used to return the Selection object, A selection represents either a selected (or highlighted) area in the document, or it represents the insertion point if nothing in the document is selected.

    So if you select nothing then you will get insertion point rather than a text. So I think it is not possible to get a word without selecting it

    Saturday, September 6, 2014 6:16 AM
  • Hello Bruno,

    I have prepared a blog post for you - Microsoft Word: How to get a selected word when you do a right click .

    Monday, September 8, 2014 2:30 PM
  • Hi Bruno


    should return the entire word in which the current selection is located. Note that your and Word's idea of what a "word" is might differ :-)

    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, September 10, 2014 5:22 PM