private bool FindNext(string textFind, bool mathCase, Word.WdFindWrap isRotation) { var sec = Globals.ThisAddIn.Application.ActiveDocument.Application.Selection.Range; sec.Find.ClearFormatting(); sec.Find.MatchCase = mathCase; sec.Find.Forward = true; sec.Find.Wrap = isRotation; if (sec.Find.Execute(textFind)) { sec.Select(); return(true); } else { return(false); } }
public static void ReplaceInDoc(Microsoft.Office.Interop.Word.Document theDoc, string ReplaceIt, string ReplaceWith) { Microsoft.Office.Interop.Word.WdFindWrap wdFindAsk = (Microsoft.Office.Interop.Word.WdFindWrap) 2; Microsoft.Office.Interop.Word.Application wordApp = theDoc.Application; var wdReplaceAll = 2; wordApp.Selection.WholeStory(); wordApp.Selection.Find.ClearFormatting(); wordApp.Selection.Find.Replacement.ClearFormatting(); wordApp.Selection.Find.Text = ReplaceIt; wordApp.Selection.Find.Replacement.Text = ReplaceWith; wordApp.Selection.Find.Forward = true; wordApp.Selection.Find.Wrap = wdFindAsk; wordApp.Selection.Find.Format = false; wordApp.Selection.Find.MatchCase = false; wordApp.Selection.Find.MatchWholeWord = false; wordApp.Selection.Find.MatchWildcards = false; wordApp.Selection.Find.MatchSoundsLike = false; wordApp.Selection.Find.MatchAllWordForms = false; wordApp.Selection.Find.Execute(Replace: wdReplaceAll); }
private void ReplaceNext(string findWhat, string textReplace, bool matchCase, Word.WdFindWrap isRotation) { var sec = Globals.ThisAddIn.Application.ActiveDocument.Application.Selection.Range; if (sec.Text != null && ((matchCase && sec.Text == findWhat) || (!matchCase && (sec.Text.ToUpper() == findWhat.ToUpper())))) { sec.Text = textReplace; sec.Start = sec.End; sec.Select(); FindNext(findWhat, matchCase, isRotation); } else { FindNext(findWhat, matchCase, isRotation); } }