Replace specific text from word document

Hello,

I want to replace the highlighted fields from word document with some some other data. plzz help me out to find a way
table

Hi @sarvesh.b ,

Can you confirm Particulars and Amount will be the same. which you marked red color.

Thanks!

Yess, that will be same for all the formats.

@sarvesh.b

Did you try this

https://docs.uipath.com/activities/docs/word-replace-text

cheers

yess, this is for replace but first i need to get the highlighted texts and then replace with this activity. how do i will get that text field that is the main task.

@sarvesh.b

What does that mean?

May I know on what basis you identify those values manually?

Cheers

Hi @sarvesh.b
For your specific case, try the VB script code below.

Imports Microsoft.Office.Interop.Word

Open the document file.
Dim app As New Application()
Dim doc As Document = app.Documents.Open(“C:\MyDocument.docx”)

Loop through the tables in the document.
For Each tbl As Table In doc.Tables
Loop through the rows in the table.
For Each row As Row In tbl.Rows
Loop through the cells in the row.
For Each cell As Cell In row.Cells
Replace the value in the cell with a new value.
cell.Range.Text = cell.Range.Text.Replace(“oldValue”, “newValue”)
Next
Next
Next

Save the document and close the application.
doc.Save()
app.Quit()