Reputation: 11
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
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