G
Guest
Hi,
I'm using the bellow code to mail merge a word document and it's working
fine, where I'm openning "improvement.doc" which is just word document that
contain with some text and the merge fields at the top of the document...
after performing the merge I want to save the merged document as
"merged.doc" and close it. the problem is that my code is opening a new
document (as Letter) to do the merge and I don't know to access that document
to be able to save it and close it!!!?
I have tried to comment the : wrdMailMerge.Destination =
Word.WdMailMergeDestination.wdSendToNewDocument;
but still doing the same.
Word.Selection wrdSelection;
Word.MailMerge wrdMailMerge;
Word.MailMergeFields wrdMergeFields;
string StrToAdd;
Object oName = "C:\\improvement.doc";
wrdApp = new Word.Application();
wrdApp.Visible = true;
// Add a new document.
wrdDoc = wrdApp.Documents.Add(ref oName, ref oFalse,
ref oMissing, ref oMissing);
wrdDoc.Select();
wrdSelection = wrdApp.Selection;
wrdMailMerge = wrdDoc.MailMerge;
Object oFileName ="C:\\merged.doc";
Object oFileFormat = Word.WdSaveFormat.wdFormatDocument;
Object oTrue = true;
// Create a MailMerge Data file.
CreateMailMergeDataFile();
wrdMailMerge.Destination =
Word.WdMailMergeDestination.wdSendToNewDocument;
wrdMailMerge.Execute(ref oFalse);
wrdDoc.SaveAs(ref oFileName, ref oFileFormat, ref oMissing, ref
oMissing, ref oTrue, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing);
wrdDoc.Saved = true;
wrdDoc.Close(ref oFalse, ref oMissing, ref oMissing);
//wrdApp.Quit(ref oFalse, ref oMissing, ref oMissing);
// Release References.
wrdSelection = null;
wrdMailMerge = null;
wrdMergeFields = null;
wrdDoc = null;
wrdApp = null;
// Clean up temp file.
I'm using the bellow code to mail merge a word document and it's working
fine, where I'm openning "improvement.doc" which is just word document that
contain with some text and the merge fields at the top of the document...
after performing the merge I want to save the merged document as
"merged.doc" and close it. the problem is that my code is opening a new
document (as Letter) to do the merge and I don't know to access that document
to be able to save it and close it!!!?
I have tried to comment the : wrdMailMerge.Destination =
Word.WdMailMergeDestination.wdSendToNewDocument;
but still doing the same.
Word.Selection wrdSelection;
Word.MailMerge wrdMailMerge;
Word.MailMergeFields wrdMergeFields;
string StrToAdd;
Object oName = "C:\\improvement.doc";
wrdApp = new Word.Application();
wrdApp.Visible = true;
// Add a new document.
wrdDoc = wrdApp.Documents.Add(ref oName, ref oFalse,
ref oMissing, ref oMissing);
wrdDoc.Select();
wrdSelection = wrdApp.Selection;
wrdMailMerge = wrdDoc.MailMerge;
Object oFileName ="C:\\merged.doc";
Object oFileFormat = Word.WdSaveFormat.wdFormatDocument;
Object oTrue = true;
// Create a MailMerge Data file.
CreateMailMergeDataFile();
wrdMailMerge.Destination =
Word.WdMailMergeDestination.wdSendToNewDocument;
wrdMailMerge.Execute(ref oFalse);
wrdDoc.SaveAs(ref oFileName, ref oFileFormat, ref oMissing, ref
oMissing, ref oTrue, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing);
wrdDoc.Saved = true;
wrdDoc.Close(ref oFalse, ref oMissing, ref oMissing);
//wrdApp.Quit(ref oFalse, ref oMissing, ref oMissing);
// Release References.
wrdSelection = null;
wrdMailMerge = null;
wrdMergeFields = null;
wrdDoc = null;
wrdApp = null;
// Clean up temp file.