none
Highlight selected word in MS Word document RRS feed

  • Question

  • In my application I select word in document, then I click on button and I want to highlight this word. It works but when I have word followed by comma or dot, for example ' hello, ', in docRange.Text is only character comma (without word 'hello').

    What I am doing wrong?

    Words doc;

    doc=Globals.ThisAddIn.Application.Selection.Words; foreach (Range docRange in doc) { docRange.HighlightColorIndex = WdColorIndex.wdYellow; }


    Tuesday, April 15, 2014 2:12 PM

Answers

  • Why would you not simply apply the highlighting to the selection, directly?

    Globals.ThisAddIn.Application.Selection.Range.HighlightColorIndex = WdColorIndex.wdYellow;


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Lenkita Tuesday, April 15, 2014 4:53 PM
    Tuesday, April 15, 2014 4:21 PM
    Moderator

All replies

  • Why would you not simply apply the highlighting to the selection, directly?

    Globals.ThisAddIn.Application.Selection.Range.HighlightColorIndex = WdColorIndex.wdYellow;


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Lenkita Tuesday, April 15, 2014 4:53 PM
    Tuesday, April 15, 2014 4:21 PM
    Moderator
  • Thank you! That is what I need.
    • Edited by Lenkita Tuesday, April 15, 2014 6:28 PM
    Tuesday, April 15, 2014 4:54 PM