How to Insert a Word document at the end of another Word document

How to Insert a Word document at the end of another Word document


I need to insert one Word document at the end of another Word document.
For this I created a new Action in the WordMerge extension, called InsertDoc (see attached extension)

The problem that I have is that, no matter what I try, Word inserts the Document (always) at the beginning of another document.

I went already to the following website:, where they explain what code is needed to Insert (in that case) a paragraph at the end of the document.

So I used that code. Added 1 line to the code, so that inside that paragraph my document is inserted.
And the document is inserted at the beginning. So the insert does work, but doesn't insert on the right place.

Can anyone help me further?
Hi Eric,

I believe the second parameter of the InsertFile method takes the bookmark where you want to insert the document.

Tiago Simões
Hi Tiago,

It works now. Thanks. Greetings,
Eric van Raaij
Hi all,

I am trying to create a single word document which is automatically generated from many merged documents.

- I create the first merged document with the extension and keep that file in a binary type variable "MainDoc".
- Keep merging documents and use the InsertDoc action provided in this extension, using as parameters: (WordTemplate: MainDoc and WordData: Merge.MergedDoc)

I also added a bookmark with the name "endofdoc" in the end of the Word Template which I'm using.

Unfortunately the result is the first single merged document. I am not inserting the newly merged documents in the first merged document.

Can someone give me a little help here? Thanks in advance.

Rui Félix
Hi Rui,

You should try the WordMerge extension that I extended with the "InsertDoc" action.
I think it does exactly this what you need.

Let me know if it works for you.

Kind regards,
Eric van Raaij
Eric, thanks for your quick response.
I am using your extension but I guess I'm doing something wrong.
Do I need to do any modification or special bookmark in the original word document?

Thanks in advance.
Hi Rui,

I will try to give you some more tips, hopefully it helps. Otherwise you have to specify more in detail what does not work.

- wrdApp.Selection.EndKey(ref oUnit, ref oMovement); this moves the cursor to the end of the document. So you don't need to make use of the endofdoc bookmark. By the way, this is an build-in bookmark in each word document, so you don't have to add this bookmark to your doc either.

- Secondly, and this might be the cause of your problem, the default account under which the the Hub server runs, doesn't have enough rights to open/save word documents in certain directories on the hub server. Therefore you need to do the following: Create a local account on the Hub server. Give this account the rights it need (at least it needs to store temp files in a specify directory on the Hub Server. If you check which path is returned by System.IO.Path.GetTempFileName(), you know where you need to grant read/write rights. Now that you have a local user on the hub server with enough rights, you need to specify in each eSpace that makes use of this extension, that the eSpace should be ran under the newly created user account. You can specify this in ServiceCenter/Factory/eSpace/Runtime in the Run As part.

That should help you further I think. Make sure that after this you re-deploy your eSpace, in order to effectuate the Run As property.

Good luck!

Kind regards,
Eric van Raaij.
Everything is now working like a charm!

Thanks alot for your work, time and pacience Eric!