问题
I would like to highlight all occurrences of a given string in Microsoft Word 2010 using VSTO.
So far, I've managed to set the foreground color for the matches using the Find
facility:
Word.Find find = Application.ActiveDocument.Content.Find;
find.Replacement.Font.ColorIndexBi = Word.WdColorIndex.wdYellow;
find.Execute(FindText: "dog", MatchCase: false, Replace: Word.WdReplace.wdReplaceAll);
However, I would like to set the highlight for the matches, such as in the screenshot below:

回答1:
Set the highlight colour by setting using
Application.Options.DefaultHighlightColorIndex
to one of the wdColorIndex members (e.g. wdYellow)
Apply the Highlight colour in a Replace using
find.Replacement.Highlight = True
回答2:
If one wants temporary highlighting, one may use the HitHighlight method instead:
Word.Find find = Application.ActiveDocument.Content.Find;
find.HitHighlight(
FindText: "dog",
MatchCase: false,
HighlightColor: Word.WdColor.wdYellow);
来源:https://stackoverflow.com/questions/21063419/highlight-all-occurrences-of-a-string-in-word-using-vsto