PDA

View Full Version : Solved: Help with Automating Mail Merge



TCMills
07-27-2005, 01:00 PM
I am an extreme newbie on Office Products. I am using Word2003 with a txt file for the mailmerge datasource.

I have tried to step through the
Automating Mail Merge KB article - ran into the SQLSecurityCheck issue, and fixed that.

When I open the word document after saving the macros, nothing happens. The file looks just like it looked when I saved it before adding the macros.

Here is the file that I am using for testing....

July 27, 2005



?Salutations? ?Title? ?LastName?,



Thanks for the $?DonationAmount?.

------------------------------------

The variables above all appear in my merge txt file.

Thank you in advance for any help that you may be able to give me.

Teresa

MOS MASTER
07-27-2005, 03:37 PM
Hi and welcome to vbax! :hi:

Ok you are not telling exactly what you have done...
So I'm going to try to tell how I think you should have done things to get the automation done. (From the top so I could miss out on stuff)

First Open Word
Go to Tools | Macro | Security
Second Tab set securtiy to medium!! (Important)
Now open your mailmerge document.
Can you do a manual mailmerge? Answer yes? Great your up for the code. Answer No? Wel attach your database (Txtfile) to the document and try out things manually first. All Ok? let's proceed.
Now Open the editor Press ALT+F11
You should see the project explorer on your left. Not? (Press CTRL+R)
Now click on the + sign next to the project that has the same name as your document: eg Project mailmerge
The Word objects will unfold.
Double click on Class Module ThisDocument
Paste this code in the code pane: (Can't see the pane? Press F7)
Option Explicit
Private Sub Document_Open()
DoMailMerge
End Sub
Public Sub DoMailMerge()
Dim DocName$
DocName = ActiveDocument.Name
'Do mailmerge
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
'Close mailmerge document
Windows(DocName).Close wdDoNotSaveChanges
End Sub



Now Close the editor and save the document.
Close this document and reopen it Choose yes when asked to activate Macro's
By now you should see a newly created document with the merge data in it.
Btw..the code closes the mailmerge document after it has created a new merge document.

That should be it with the information given.

HTH, :whistle:

TCMills
07-27-2005, 04:19 PM
Thank you - the security setting fixed the problem

Go to Tools | Macro | Security
Second Tab set securtiy to medium!! (Important)
It works like a charm now.

MOS MASTER
07-28-2005, 09:27 AM
Hi Teresa, :yes

Excellent...you're welcome! :beerchug: