Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Keith - 08 Jul 2005 14:23 GMT
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
Doug Robbins - 08 Jul 2005 18:09 GMT
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

Signature

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

> Hi,
>
[quoted text clipped - 12 lines]
>
> Keith
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.