private void dgvComments_CellEnter(object sender, DataGridViewCellEventArgs e) { string id = dgvComments[0, e.RowIndex].Value.ToString(); Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument; Word.Find find = doc.Content.Find; find.ClearHitHighlight(); find.HitHighlight(FindText: id, MatchCase: true, HighlightColor: Word.WdColor.wdColorYellow, MatchWholeWord: true); }
/// <summary>Performs search highlighting in an open mail item. /// </summary> /// <param name="inspector">The inspector for the open item.</param> /// <param name="searchText">The text to highlight.</param> private void FindInInspector(Outlook.Inspector inspector, string term) { if (inspector == null || string.IsNullOrWhiteSpace(term)) { return; } if (inspector.IsWordMail()) { Word.Document doc = inspector.WordEditor as Word.Document; Word.Range wdRange = doc.Application.Selection.Range; Word.Find wdFind = wdRange.Find; wdFind.Format = false; wdFind.MatchCase = false; wdFind.MatchWholeWord = false; wdFind.HitHighlight(term, HighlightColor: Word.WdColor.wdColorYellow); } }