Link to home
Create AccountLog in
Avatar of Patricia Timm
Patricia TimmFlag for United States of America

asked on

Using mail merge to auto populate from one word document to another

I have 2 MS word forms. I need to auto populate the word form with file number to the word form without file number. They are seperate forms with different data but I am tired of cutting and pasting. Can I use mail merge to do this and if so how? Thanks

Avatar of Eric Fletcher
Eric Fletcher
Flag of Canada image

I'm not sure mail merge is the best method to use — but your question may need more clarification to be sure.


If I am interpreting it correctly, you would like to have a template that creates a new Word document using variable information (specifically, a file number) from a data source document being maintained separately. The new document needs to include the file number in various locations where you have set them within the master document template.


Is the data source document made up of a specific list of the file numbers to be used or is it just using the next sequential number? 


If the former, your master document template could modify the data source document each time it generates a new document to (at least) flag the number as being used and also prepare a new document containing the file number wherever you need it.


For example: An AutoNew* macro in the master document template could open the data source document; select & cut the top paragraph containing the next available number; jump to the end to create a new paragraph with a "used" prefix (and date & time if you want an audit trail), then paste the cut value before saving the data source document. Then it could use Find & Replace in the new document (created from your master document template) to find each instance of a code for the filename and replace it with the contents of the clipboard (which would be the file number from the fata source). This way, your data source document would be updated so the next master document would use the number at the top (and the used file numbers would be at the bottom). The new document created would contain the specific unique file number wherever you wanted it to be.


If the latter, the data source document could be just updated by an AutoNew macro in your master document template.


For example: the AutoNew macro would open a data source document to read the last number used, increment it, save it as a variable, write it to the end of the list (again with date & time if you want an audit trail), and resave the file. Then the variable could be used in the same way as above to use F&R to populate every instance of a code in your new master document with the variable's value.


Either way, you'll need to use some VBA, but it shouldn't be particularly complicated. Keep in mind that if you need to include the file number in locations other than within the main body (i.e. in headers, footers, text boxes, etc.), you'll need to ensure that the find and replace operations act on those story types. (See wdStoryType enumeration for the various story types.)


*If a Word template contains a macro named "AutoNew", it will be executed only once when the template is used to create a new document. 

Avatar of Patricia Timm

ASKER

First thanks for the detailed response and you gave me a couple of good ideas.

I am not sure how to go about this but I have a word document already created on an oracle database. I am thinking I upload it to my one drive always keeping it open in the same place. One Drive Source document folder. That way I dont have to open the document with VB code. The document I downloaded as a word document looks like this


June 16, 2023


Donna Fictious                                                                   File number: 88888888

55555 S Drive

Madison WI 53234


Dear Donna Fictious

As an appointed fid for Jane Doe, you are etc etc

Next I have a company already created word document (template with a header, footer, etc and verbage that I have to keep

The second word document looks like this


June 16, 2023


Currently there is nothing here so I have to copy and paste Donna Fictious (this is the part I would like to automate)

Donna Fictious

55555 S Drive  - again cutting and pasting

Madison WI 53234  again copying and pasting

Fid of Jane Doe - again copying and pasting


I would think there might be an easy way to do this but not sure - of course automating is never easy until its done then you r forever thankful. I appreciate any suggestions you might have 


File number - again cutting and pasting

Every day the letters are different people and different file numbers (not sequential or automated so one day could be 33579 and the next 67013)


These in their original state are pdf's and I am saving them as word docs as I thought it would be easier to maybe use mail merge or vb for apps. I am rusty with vb for apps in macros but have used before. I do have dc writer in adobe but it seems limited in its ability to extract info from one source and populate another pdf. The find and replace concept is interesting if I could maybe create a text box 




ASKER CERTIFIED SOLUTION
Avatar of Eric Fletcher
Eric Fletcher
Flag of Canada image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer