1 public bool SearchReplace(string strOldText, string strNewText)
2 {
3 object replaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
4 object missing = Type.Missing;
5
6 //首先清除任何现有的格式设置选项,然后设置搜索字符串 strOldText。
7 this.oWordApplic.Selection.Find.ClearFormatting();
8 oWordApplic.Selection.Find.Text = strOldText;
9
10 oWordApplic.Selection.Find.Replacement.ClearFormatting();
11 oWordApplic.Selection.Find.Replacement.Text = strNewText;
12
13 if (oWordApplic.Selection.Find.Execute(
14 ref missing, ref missing, ref missing, ref missing, ref missing,
15 ref missing, ref missing, ref missing, ref missing, ref missing,
16 ref replaceAll, ref missing, ref missing, ref missing, ref missing))
17 {
18 return true;
19 }
20 return false;
21 }
22