Mail Merge Data Source Missing after Document Generation

C

cvsudheer

I need to generate a document from a Custom Template.
The Custom Document Template has got a Mail Merge Data Source
attached.

A new document can be generated from an existing template as follows.

* Add a reference to Word 11 Object Library under COM Tab

Object dotPath = @"C:\AsposeSample\TestNoticingTemplate.dot";
Object documentPath = @"C:\AsposeSample\Document1.doc";

object missing = System.Reflection.Missing.Value;
MSWord.ApplicationClass wordApp = new MSWord.ApplicationClass();
wordApp.DisplayAlerts =
Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
wordApp.Visible = false;

wordApp.Application.Documents.Add(ref dotPath, ref missing, ref
missing, ref missing);
wordApp.Application.ActiveDocument.SaveAs(ref documentPath, ref
missing, ref missing, ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing);

Object saveSetting = MSWord.WdSaveOptions.wdSaveChanges;
Object originalFormat =
MSWord.WdOriginalFormat.wdOriginalDocumentFormat;
Object routeDocument = true;

wordApp.Application.ActiveDocument.Close(ref saveSetting, ref
originalFormat, ref routeDocument);
wordApp.Application.Quit(ref saveSetting, ref originalFormat, ref
routeDocument);
wordApp = null;

Here I get the document from the template, but the generated document
does not have the "Mail Merge Data Source" binding, that was present
in the template.
So the user has to manually add the data source for Mail Merge. The
purpose of creating a template was to avoid this step.

I am using Word 2003.

Please let me know if any of you got a solution for this.

Thanks.!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top