How to replace multiple words while working with 3 documents?

Hi All,

Would need some advice on a case that I am currently working on please.

There are 3 documents that I am working with.

  1. 1 passage - Doc A (the passage can change)
  2. 1 list of words to pick out from the passage - Doc B (new words can be added in from time to time)
  3. 1 list of words to replace the picked out words - Doc C

The objective is for UiPath to go through the passage, picked out certain words, to replace the words and save the passage with replaced words in a new document.

For example,
Hi, my name is A. I live in an urban area. On a sunny day I went out to work and went to school to study at night after work. However, I left my textbook at home and could not concentrate in class. After class, I went to a nearby coffeeshop to have supper and went home to rest after that.

The above passage will be read in UiPath, then 2 other word documents (or 1 excel document with 2 columns/sheets) will be read to pick out the words in the passage and to be replaced:

For example,
image

Lastly, to save into a new document or write into a new document.

–

The issue that I am facing is not being able to pick out and replace multiple words.

  1. I have tried using the “word application scope” range of activities to read the 3 word documents, replace text and to save as a new word document. I am able to get 1 word to be replaced, but unable to get multiple words to be picked out and to replace. There is no error given when running the activities but the replacing of words part couldn’t work, only able to save into a new document.

  2. For Doc B & C, I tried to list the words out in an excel and for that excel to be read and to use “replace text in document” activity to do the job. However, as Excel’s variable type is DataTable and “replace text in document” activity works only with String, this method can’t seems to work as well.

Is there any other method that I can explore?

Really appreciate any suggestion or guidance.

Thank you.

@Alearns

So the second method what ypua re doing would work…

So this is how w
You would approach it…

  1. Read all the data from the excel into datatable…basicaly it contains two columns one to find and other to replace…
  2. Use a for eqch row in datatable activity… and pass the above dt.
  3. Inside the loop use word doc replace text activity… give the word to find as CurrentRow("Words to pick out").ToString and in the replace field use CurrentRow("Words to replace").ToString

Hope this helps

Cheers

Hi @Anil_G, thanks a lot, it works!

However, I have encountered another issue of the original passage document being replaced as well.

I would like the original passage document to stay as it is thus have a new document written after the replacement of texts.

Is there an activity that I can input to stop the original file being replaced as well? Tried searching online but couldn’t manage to find much on this.

Thank you.

@Alearns

First use a copy file activity …and create a new file…then perform the actions on the new file

Hope this helps

Cheers

Hi @Anil_G

Thank you for your help.

This solution has resolved the issues faced.

Have a great week ahead.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.