Word Mail Merge

“Learn something new every day.” That is my personal motto and I really feel that everyday I learn something new. Well, the other day I learned about MS Word’s Mail Merge capabilities. Word’s Mail Merge feature allows you to define a Word document template to be used for every row in a data source file. Your data source can be an Excel file or a Word document with a single table. Once you have a data source file you can merge it with the template using the following Visual Basic script code:

Sub OpenWord(fileName, datasource)
   Set Word = WScript.CreateObject("Word.Application")
   Word.Visible = True
   Set doc = Word.Documents.Open(fileName)
   doc.MailMerge.OpenDataSource(datasource)
   doc.MailMerge.Execute True
End Sub

Related posts:

  1. More Ways To Open A Doc
  2. Print HTML Using IE
  3. The Word Is POI
  4. Word To PDF
  5. TechKnow Year In Review 2005

This entry was posted in DotNET, TechKnow, Visual Basic. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Comment

  1. Posted March 23, 2009 at 9:02 am | Permalink

    But you can not make a script that will automatically perform. Always when you run the script asks you to select an excel sheet for the merge

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*