Hiren Kotadia
Hiren Kotadia

Reputation: 11

How to get selected text from Word Document in C# based Word Add-In?

I am developing a MS Word Add-In. For which, I would like to know how to get the text that is currently selected in the word document and then perform my application specific action on it.

Thank you, for your help.

Upvotes: 1

Views: 7414

Answers (1)

astro boy
astro boy

Reputation: 1430

In your Word add-in project in Visual studio use the following code on your trigger event to get the selected text:

        string selectText = string.Empty;
        Word.Selection wordSelection = this.Application.Selection;
        if (wordSelection != null && wordSelection.Range != null)
        {
            selectText = wordSelection.Text;
        }

note: the above code hasn't been tested.

Upvotes: 6

Related Questions