I currently have a case whereby the bot will read 2 documents -
Word document of a passage
Excel sheet, list of words to be picked out in the passage
The bot will run through the passage and see if any of the words listed in the excel sheet appears in the passage. If it does, we would want the bot to highlight the words and we will check it at the end of the process.
As I am quite new to RPA, I can’t seem to find a way to do it. Tried searching online for tutorials but unable to find suitable ones as well.
Really appreciate some guidance on this case please.
Keep the list of words in an excel file, read the file, get the data & store the list of words in a variable (array or list).
Use Word Application Scope to open the word document & read the contents. Save it in a variable as well.
Using ForEach, iterate through the list of words. Inside the loop, search for the word using .Contains() function. If the word is available -
i. Use the Replace Text activity to highlight the word by wrapping it with some special characters such as and .
By the end, use Set Text activity to keep the replaced word doc as the latest.
Could you try to use the below Code Snippet in Invoke Code Activity (Language set to CSharp)
try
{
var wordApplication = new Microsoft.Office.Interop.Word.Application() { Visible = false };
var myDocument = wordApplication.Documents.Open(in_FilePath);
foreach(string word in in_WordsToColor)
{
Microsoft.Office.Interop.Word.Find find = myDocument.Content.Find;
find.Execute(word);
if (find.Found)
{
Microsoft.Office.Interop.Word.Range range =(Microsoft.Office.Interop.Word.Range) find.Parent;
range.Select();
myDocument.Application.Selection.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorRed;
}
}
myDocument.Save();
wordApplication.Quit();
}
catch( Exception e)
{
Console.WriteLine(e.Source.ToString()+" "+e.Message.ToString()+" "+e.TargetSite.ToString());
}
Here, we would need to pass two arguments to Invoke Code Activity, in_FilePath which should be the file path of the Word Document and in_WordsToColor, an Array of String type which should contain the array/list of words that you would want to color.