D
Dave
I'm trying to do a find/replace by automating Word from a C# application.
It works fine as long as my find/replace text is alphabetic. If I try to do
a find/replace using a string such as "C#", I get an error: "The Find What
text for a Find All Word Forms search can only contain alphabetic letters.".
I tried enclosing the string in quotes, but that doesn't work either. That
actually will cause the problem with text that otherwise works - it doesn't
like the quotes either.
Here's my code (this code highlights all instances of "text" in red/bold):
Object oReplaceAll =
Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
Object oText = text;
Object oReplaceText = text;
wordDoc.Select();
msWord.Selection.Find.Text = oText.ToString();
msWord.Selection.Find.Replacement.Text = oReplaceText.ToString();
msWord.Selection.Find.Replacement.Font.Bold = 1;
msWord.Selection.Find.Replacement.Font.Color =
Microsoft.Office.Interop.Word.WdColor.wdColorRed;
msWord.Selection.Find.Execute(ref oText, ref oFalse, ref oFalse, ref
oFalse, ref oFalse, ref oTrue, ref oTrue, ref oFalse, ref oTrue, ref
oReplaceText, ref oReplaceAll, ref oMissing, ref oMissing, ref oMissing, ref
oMissing);
You can do what I want from within word itself - how do you call
find/replace and allow non-alphabetic characters?
- Dave
It works fine as long as my find/replace text is alphabetic. If I try to do
a find/replace using a string such as "C#", I get an error: "The Find What
text for a Find All Word Forms search can only contain alphabetic letters.".
I tried enclosing the string in quotes, but that doesn't work either. That
actually will cause the problem with text that otherwise works - it doesn't
like the quotes either.
Here's my code (this code highlights all instances of "text" in red/bold):
Object oReplaceAll =
Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
Object oText = text;
Object oReplaceText = text;
wordDoc.Select();
msWord.Selection.Find.Text = oText.ToString();
msWord.Selection.Find.Replacement.Text = oReplaceText.ToString();
msWord.Selection.Find.Replacement.Font.Bold = 1;
msWord.Selection.Find.Replacement.Font.Color =
Microsoft.Office.Interop.Word.WdColor.wdColorRed;
msWord.Selection.Find.Execute(ref oText, ref oFalse, ref oFalse, ref
oFalse, ref oFalse, ref oTrue, ref oTrue, ref oFalse, ref oTrue, ref
oReplaceText, ref oReplaceAll, ref oMissing, ref oMissing, ref oMissing, ref
oMissing);
You can do what I want from within word itself - how do you call
find/replace and allow non-alphabetic characters?
- Dave