Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mailmerge in MS Word using ASP.NET!

Status
Not open for further replies.

maniacmaniar

Programmer
May 9, 2008
6
US
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. They will provide a template to do the merge. My code is able to do the merge using the template provided, but the problem is that the mailmerge toolbox in MS Word is disabled (grayed out) so the users cant add/remove any fields. I need this to be enabled. 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"; // the filename variable will contain the name of the template, but for example purposes, I have hardcoded it.

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;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top