Wrox Programmer Forums
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 22nd, 2005, 01:56 AM
Registered User
Join Date: Jun 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Word Mail Merge Automation using ASP.Net


I am trying to automate word mail merge and redirecting the output to the printer. Since I am making use of ASP.Net as technology, so word application is not visible to me. But when print command fires from the code, a print dialog box opens up in the background, which makes the system to hang. Please do the needful.

Dim wrdSelection As Word.Selection
        Dim wrdMailMerge As Word.MailMerge
        Dim wrdMergeFields As Word.MailMergeFields

        Dim StrToAdd As String

        ' Create an instance of Word and make it visible.
        wrdApp = CreateObject("Word.Application")
        wrdApp.Visible = True
        wrdApp.DisplayAlerts = 0

        ' Add a new document.

        wrdDoc = wrdApp.Documents.Open("ThankYou.doc")

        wrdSelection = wrdApp.Selection()
        wrdMailMerge = wrdDoc.MailMerge()

        ' Create MailMerge Data file.

        Dim strPrinterName As String
        Dim objDialog As Object
        strPrinterName = wrdApp.ActivePrinter

        wrdApp.ActivePrinter = "Dummy"
        wrdMailMerge.SuppressBlankLines = True

        wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToPrinter

        wrdApp.ActivePrinter = strPrinterName

        ' Release References.
        wrdSelection = Nothing
        wrdMailMerge = Nothing
        wrdMergeFields = Nothing
        wrdDoc = Nothing
        wrdApp = Nothing

Old April 28th, 2006, 10:41 PM
Registered User
Join Date: Apr 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts


Did you solve this problem in the end? I'd be interested to know the solution.


Old December 17th, 2007, 02:13 AM
Registered User
Join Date: Dec 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

Hi i want to do the mail merge using a mSword template and CSV file and save the resulting document as PDF.How can i do that .Please advice me .


Old November 29th, 2013, 07:18 AM
Registered User
Join Date: Nov 2013
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Re: Word Mail Merge Automation

Hi, I also encountered some issues when I used a .NET word interop in ASP.NET app.
I found that it is not supported: MS support page (Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications on server side), but they provide some alternatives to server-side automation.
You could try this alternative VB.NET Word component to achieve mail merge in .NET from the server side, here is a small example:
' Load DOC document.
Dim document = DocumentModel.Load("ThankYou.doc")

' Execute mail merge.
Also you could easily print Word with .NET without PrintDialog popping out, just use this:
Additionally, aditya_raj you can also check this out because I found its mail merge process to be very flexible and customizable.
You could for example read CSV file into a DataTable and then use it as an data source for a mail merge execution, after which you could convert Word file to a PDF in .NET like the following:

Similar Threads
Thread Thread Starter Forum Replies Last Post
Access launching Word for mail merge Loralee Access 8 November 14th, 2005 04:24 PM
Mail Merge with MS Word bezaman Classic ASP Basics 1 October 6th, 2005 04:13 PM
Access to Word Mail Merge Automation kareltje Access VBA 6 June 9th, 2005 04:54 AM
Wrap Up feature (like Word Mail Merge) jmurdock BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 June 28th, 2004 03:20 PM
Use ASP to create Mail Merge in Ms Word eapsokha Classic ASP Professional 3 March 9th, 2004 07:45 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.