Hi,
Welcome to our Microsoft Q&A platform!
You can try to add a space like this:
object findStr3 = "No ";
Thanks.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
This is my Code it works but I have a problem at the third part when I try to change the word 'No' color to red it changes any word that includes 'No' for example 'Not Isolated' was Effected by this and its color was changed
how can i specify that i want only the word 'No' to be red?
object findStr = 'Not Applicable';
object findStr2 = 'N/A';
object findStr3 = 'No';
while (fileOpen.Selection.Find.Execute(ref findStr))
{
fileOpen.Selection.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdRed;
}
fileOpen.Selection.Start = 0;
while (fileOpen.Selection.Find.Execute(ref findStr2))
{
fileOpen.Selection.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdRed;
}
fileOpen.Selection.Start = 0;
while (fileOpen.Selection.Find.Execute(ref findStr3))
{
fileOpen.Selection.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdRed;
}
Hi,
Welcome to our Microsoft Q&A platform!
You can try to add a space like this:
object findStr3 = "No ";
Thanks.
Maybe execute ‘fileOpen.Selection.Find.MatchWholeWord = True’ before starting the loops.
But I tried "No ",it works well.Please see my code:
private void Button_Click(object sender, RoutedEventArgs e)
{
MSWord.Application wordApp = new MSWord.Application();
MSWord.Document wordDoc;
wordApp = new MSWord.Application();
wordApp.Visible = false;
Object Nothing = Missing.Value;
wordDoc = wordApp.Documents.Open(Environment.CurrentDirectory + "\\test.docx", ref Nothing, ref Nothing, ref Nothing, ref Nothing);
//object findStr1 = "Not Applicable";
//object findStr2 = "N/A";
object findStr3 = "No ";
//while (wordApp.Selection.Find.Execute(ref findStr1))
//{
// wordApp.Selection.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdDarkRed;
//}
//wordApp.Selection.Start = 0;
//while (wordApp.Selection.Find.Execute(ref findStr2))
//{
// wordApp.Selection.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdBlack;
//}
//wordApp.Selection.Start = 0;
//wordApp.Selection.Find.MatchWholeWord = true;
while (wordApp.Selection.Find.Execute(ref findStr3))
{
wordApp.Selection.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdRed;
}
wordDoc.Save();
wordDoc.Close(false, Nothing, Nothing);
wordApp.Quit(false, false, false);
}
Thanks.