How do I read a Word document into a variable keeping the format

I’m trying to perform the following steps:

  • Read Word docx
  • Read Excel xlsx
  • Loop through Excel
  • For each row in Excel, replace text in Word document
  • Write Word doc to new page in one Word document

Basically what I’m doing is mimicking a mail merge and want to end up with one multi-page Word document for easy printing. Yes there’s a reason why we aren’t just doing an actual merge in Word, which I unfortunately cannot share - just know there’s a valid reason.

The problem I’m having is I can read the Word document (Read Text), do the replace, and append to the output Word document. But it loses all formatting, images, etc.

Is there really no way to do this, without sending mouse clicks and hotkeys with Word open?

I think can not keeping the format of old files, you need to invoke vb.net code to write the format to new file.

Hi Postwik,

If you perform operation in Word application scope, and perform replace text activity in same word, it will preserve the state ( formatting). But if you try to copy the content to another word file using read text activity preserving the content , I don’t think it possible.

Regards,
Tuhin

I agree with u

Hi Postwick,

I have similar operation to perform. Could you please help me with this?