Formatting texts in word doc using replace text activity

Hi all

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?

Thank you.

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,

Hi @Alearns ,

Could you let us know with some sample Data and what words are needed to be formatted and what is the format to be done ?

We could do a similar approach as provided in the below Post as well :

Hi @Alearns

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:

  1. Read Excel Data: Use the “Read Range” activity to read the list of words from the Excel sheet into a DataTable in UiPath.

  2. Iterate Through DataTable: Use a “For Each Row” activity to loop through each row in the DataTable.

  3. 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.
  4. 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.

Thanks!!

1 Like

hi @Nitya1

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?

Thank you.

Hi @supermanPunch

Thank you for providing the details.

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.
image

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.

Thank you.

@Nguyen_Van_Luong1

Thank you for providing the details.

Will give it a try.

Can you share to me a sample input and expect output?
I will test for you

Hi @Nguyen_Van_Luong1

Apologies for the delayed response. Really appreciate your help on this.

Please find the attached files for the WIP, notes, etc:
7) Sample Runs.zip (146.2 KB)

Currently I am only able to get the replacement of words to work, unable to format the words in any way.

Thank you.