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
Enjoy. Share. Be Happy.
  • Twitter
  • Facebook
  • StumbleUpon
  • del.icio.us
  • Tumblr
  • Google Bookmarks
  • FriendFeed
  • Yahoo! Buzz
  • Reddit
  • Digg
  • HackerNews
  • Suggest to Techmeme via Twitter
  • LinkedIn
  • Ping.fm
  • Identi.ca
  • Mixx
  • Furl

Related posts:

  1. More Ways To Open A Doc
  2. The Word Is POI
  3. Print HTML Using IE
  4. Word To PDF
  5. WordprocessingML

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 *

*
*