I have an excel file with first name, D.O.B, last name and I have a word letter template, like so.
Dear Regards, rpa_monkey
I’m trying to insert the First name after the “Dear” Then insert the "D.O.B in the next line.
The following is the approach I’ve taken to solving this.
- I read the excel file in
- Add the information from excel to a data table.
- Then iterate through the data table using a For each loop.
- Get the Firstname and D.O.B
- Then I open the word document in word application scope
- Use replace to Replace “Dear” with "Dear " + FirstName &vbNewLine & D.O.B
- Then export it as a .pdf
This works for the first iteration, but after that, the names get longer. ie.
It goes from Dear John -> Dear John Sam -> Dear John Sam Mary etc. etc. How can I make sure, it’s replacing The whole line and not just adding on to the existing one?