How to create MS Word document automatically by inserting text file content to the word document

There are many situations you may want to automate the MS Word document creation. In my previous posts, I have explained how to automate document generation using VBA. It was to create a new document. Every time you run the VBA code, it will create a new MS Word file.

How to create a template in MS Word

Now, I will explain how to insert a text file into the document as is at a specified location into an existing document. This is very useful if you are modifying an existing document. The main feature of this VBA is, it can insert new content at a specific location. That means you can insert new content into any part of the existing document, not just append the new content at the end of the file. The first step is to create a bookmark in the word document where the text file content will be pasted. Then, open the text file using VBA code and paste the content at the bookmark. Save the file with a different name. Before saving optionally you can remove the bookmark.

Below video shows details steps to insert a text file into MS word document


How to make a copy of current document MS Word automation with dynamic fields

How to make a copy of the current document using VBA in MS Word

It makes use of the dynamic fields to create a new document with different values. The MS word document can be used as a template file. Using this template you can create a new document without much effort. Click on the button and fill the necessary information. And the document will be created at the specified location. Edit the macro and modify the hardcoded values as per your needs. Change the location of the target file. The new file will be created and stored at this location 

This video explains the detailed steps to create and use this template.




Part 1:  how to use dynamic fields in ms word
https://www.youtube.com/watch?v=MlzyKniRckQ





you can download the ms word file here

https://drive.google.com/open?id=0B4UB3eOhhY26ZWhySlpROWlidEU

How to create a template in MS Word



This video shows how to create a template in MS Word. Templates are useful for automating word documents. When you have to create multiple documents with the same content but with a few new items, this template will come handy. For example, if you want to create sub-contract documents, with different clients, only the client-specific detail will change and the document format will remain the same. In this, you have to change only the client information, other things like contract rules will remain the same. In the template fill the client-specific information the generate the new document for the new client by just pressing a button. You can store repetitive values somewhere in the bookmark and place them wherever needed. The macro or the VBA code is very simple and it can be extended to add other functionalities.

There are 3 steps to create MS word templates.
Step 1
Create a section of bookmarks, which hold the value you enter. These are hidden.

Step 2
Create a field code to populate the values. Use ASK filed to get the values from user and store them in the bookmarks created earlier.

Step 3
Create fields where you want to place the values stored in bookmarks. use the FORMULA field to get the value from bookmark and place them wherever you want
code REF Bookmark name
Finally, you can create a macro to update all the values. For this, you can create a button and assign the code to it.

VBA code
-------------------------------------
Private Sub Update_Click()
Fields.Update
End Sub
-------------------------------------