I am using the following code to find some strings in my document:
Application application = Addin.Application;
Document document = application.ActiveDocument;
Range rng = document.Content;
rng.Find.ClearFormatting();
rng.Find.Forward = true;
rng.Find.Text = findText;
while (rng.Find.Execute() && rng.Find.Found)
{
//here: rng.Text == findText
//however rng.Find.HitHighlight(findText, WdColor.wdColorAqua);
//highlights all occurrences in the document, not in the current range
}
as the comments in the code state, I'd expect rng.Find.HitHighlight(findText, WdColor.wdColorAqua);
to only work on the current range but instead it executes on the whole document.
Interestingly if I start from a different range this works as I would expect... ie.
Range rng = document.Content.Paragraphs.First.Range;
rng.Find.HitHighlight("video", WdColor.wdColorAqua);
will only HitHighlight
the findText
in the first paragraph.
This is inconsistent... Any ideas on how to perform HitHighlight
only on the range selected using Find
?
NOTE: I tried this in a NetOffice addin and I get the same behavior.