I would like to format multiple words in word document. The list of words to format will be referenced from an excel sheet.
Understand that perhaps word package does not have that option now, but if I were to use replace text and add things like or somewhere along this idea, is it possible?
I did an initial try and could not get it to work, however, would like to reach out to see if there’re any possibilities.
If not, is there any other way to format text besides sending hotkeys?
Hi @Alearns ,
If you know about macros a little or if you can at least record a macro. You can inject VBA code or just run a macro and have the results you’re looking for.
regards,
To format multiple words in a Word document based on a list of words from an Excel sheet in UiPath, you can indeed use the “Replace Text” activity. Here’s how you can approach it:
Read Excel Data: Use the “Read Range” activity to read the list of words from the Excel sheet into a DataTable in UiPath.
Iterate Through DataTable: Use a “For Each Row” activity to loop through each row in the DataTable.
Replace Text: Inside the loop, use the “Replace Text” activity to find and format the words in the Word document. Set up the activity as follows:
Input: The Word document’s text.
Find: Use the current word from the Excel sheet (access it with row("ColumnName").ToString() where “ColumnName” is the name of the column in your DataTable containing the words to be formatted).
Replace With: The formatted text or the desired formatting.
Update Word Document: After replacing the text, you can update the Word document by overwriting it or saving it as a new document, depending on your requirements.
This approach allows you to format text based on a list of words from Excel without relying on hotkeys. Make sure to configure the “Replace Text” activity correctly, including specifying the formatting you want for the matched words.
Thank you for taking the time to provide the details.
We tried this as our first method, the replaced words are formatted in the excel sheet, however, did not appear as formatted in the word document, though the words are replaced successfully but there’s no formatting.
Is there any specific thing that we have to indicate in the DataTable?
It is the same concept as the thread that you mentioned in your reply.
Actually that was asked by me as well.
Initially we wanted to “highlight” multiple words in the document but understand it is not as doable thus we changed to “changing font color” then “bolding” of words.
However, using the code given, we were met with a lot of errors:
When we tried to use the code on a fresh clean project, it works though. However, it is unable to change the font color of a word with multiple instances which is 1 of the criteria that we need.
I am still in the midst of trying. For this: in_WordsToColor , an Array of String type which should contain the array/list of words that you would want to color.
If I am unable to put excel file path under the variable for the bot to read, what type of file should I put that contains the list of words the bot needs to color?
My apologies if I seem to be unclear as I am still quite new to UiPath.