Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Mailmerge in MS Word using ASP.NET!

Last post 05-09-2008 9:53 PM by maniacmaniar. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 05-09-2008 9:53 PM

    Mailmerge in MS Word using ASP.NET!

    Hi guys: I have a problem that I havent been able to resolve. Basically, I have an ASP.NET application that the users will use to select records and then do a mail merge. My code is able to do the merge, but the problem is that the mailmerge toolbox in MS Word is disabled (grayed out). I need this to be enabled because I want to give the users the ability to add/remove any fields from the document.  It would be great if someone can help me in this issue. By the way, I am using MS Word 2003 and running XP.

     Thanks.

     Here is the code that I am using:

    ApplicationClass myWordApp = new ApplicationClass(); // our application

    Document myWordDoc = new Document(); // our document

    object missing = System.Reflection.Missing.Value; // our 'void' value

    object filename = "C:/sample_merge_doc.doc";

    object destination = "C:/MyNewDocument.doc"; // our target filename

    object notTrue = false; // our boolean false

    myWordApp.Visible = false; // tell word not to show itself so that we can do everything in the background

    myWordDoc = myWordApp.Documents.Add(ref filename, ref missing,ref missing,ref missing);

    object oconn = "DSN=dsnName;uid=uname;pwd=passwd;";

    Object oFileFormat = System.Type.Missing;

    Object oMissing = System.Type.Missing;

    Object oFalse = false;

    Object oTrue = true;

    Object oSubType = System.Type.Missing;

    string dsName = null;

    myWordDoc.MailMerge.OpenDataSource(dsName, ref oFileFormat, ref oMissing, ref oTrue, ref oMissing,

    ref oFalse, ref oMissing, ref oMissing, ref oTrue,

    ref oMissing, ref oMissing, ref oconn, ref query, ref oMissing, ref oMissing, ref oSubType);

    myWordDoc.MailMerge.Execute(ref oFalse);

    myWordApp.Visible = true;

    • Post Points: 5
Page 1 of 1 (1 items)