Need to load a doc and run a Mail Merge from VB

K

Keith

Hi,

I have set up a mail merge document in MS Word I'll call MyTemplate.doc I
run Mail Merge to merge with a text file called MyData.txt.

I'm using VB to generate a new MyData.txt file. Has anyone ever written
code that will load MyTemplate.doc, instruct MyTemplate to mail merge into a
new document, then print the new document, save it and exit the new
document and MyTemplate.

Also, I may have to set some of the printer settings before I print it.

Thanks,

Keith
 
D

Doug Robbins

The following is untested, but should do what you want:

Dim mdoc As Document
Set mdoc = Documents.Add("MyTemplate.doc")
With mdoc.MailMerge
.OpenDataSource Name:="mydata.txt"
.Destination = wdSendToNewDocument
.Execute
End With
ActiveDocument.PrintOut
ActiveDocument.Save

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top