? How to use MS Word merge field results after merge is completed

I have a 3rd party app that brings over data to a word document and fills the merge fields that we selected from a list to help create our own letters.  What I need to do is take the information in that letter that has been filled into the merge fields and calculate a few numbers and then fill a table with the information.

So the question is how do I access the information in the merge fields in vba, so that I can fill other custom  fields into the letter.  So I need the letter to load first with the data, then execute the vba code after the word document has been loaded.

Hoping someone has had to do something like this.  Not sure what sub to call my sub from when the document is loaded, and how to access the fields.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


The event  for it is


see example


Res = Doc.MailMerge.DataSource.DataFields("ClientNumber").Value

A third party application might be doing something different, but the text that has been placed in Result document during the Word Mail Merge operation is not especially distinguished from the fixed text from the Main document. That means that there is no simple way to pull the merge text from the result document.

Some workarounds - the best would depend on your exact situation

1. You could consider using a special Style for the merge fields and looking for that in the result document. Quite a lot of work to set up.
2. Compare the Main and the Result documents. Not particularly easy.
3. Requery the datasource separately just before or after the merge. This would normally be the simplest method.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mgmhicksAuthor Commented:
ok, I have this formula that gives a syntax error and I don't know why.  =datediff([renewal_begins],[current_lease_ends],"d")

I have a Renewal_Begins merge field and a current_lease_ends merge field.    I did try it without the brackets and that still did not work.

I not sure how to get the code to stop or show message box after mail merge just to see if I can get code to run on this.

I'm now trying to create my own fields, like I need to know the number of days in the renewal_begins month, or the number of days in the current_lease_ends date.  

This 3rd party app is creating the word document for us, in but how can I access the data that is coming over and maybe manipulate that, instead of the merge fields.

hope that helps clear up my situation.
Eric FletcherCommented:
If the application is only occasional, or too ad hoc to warrant an automated solution, consider using the little-known Spike feature of Word. The name comes from a mounted spike used to pin notes. I use it to pull selected information from Word invoices into Excel. Here's how...

1. Select the first element you need and press Ctrl-F3. The selected content will disappear, but it actually becomes the first item on the spike. Repeat for each element you need.

2. Move to an empty paragraph mark and press Shift-Ctrl-F3. Each of the elements added to the spike will have their own paragraph in the order they were spiked.

3. To get this to my Excel sheet, I select and copy the dumped spike items and paste it into Excel.

Be sure to close the Word document without saving after you use this!

Note that Spike does not use the clipboard, and its content is unavailable once you have dumped it with Shift-Ctrl-F3.

It is difficult to understand your comment in terms of your question. If you have difficulty in producing a datasource sheet, then it would be better to raise a separate question
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.