Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > save word after mail merge

Reply
Thread Tools

save word after mail merge

 
 
=?Utf-8?B?QmFkaXM=?=
Guest
Posts: n/a
 
      04-04-2007
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.

 
Reply With Quote
 
 
 
 
Ben Rush
Guest
Posts: n/a
 
      04-05-2007
I think you're in the wrong newsgroup.

Try microsoft.public.office.*

--
~~~~~~~~~~~
Ben Rush
http://www.ben-rush.net/blog


"Badis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 2003 Help -- Mail Merge blackX Microsoft Certification 0 07-21-2008 05:50 PM
MS Word mail merge automation giovanni.chiozza@libero.it Python 0 02-16-2007 03:47 PM
MS Word mail merge automation Steve M Python 2 10-05-2005 06:25 PM
Any ASP.NET Example? Automate Word to Perform a Client-Side Mail Merge Martin Feuersteiner ASP .Net 0 07-19-2004 03:07 AM
How to emulate Word mail merge in HTML? VB Programmer ASP .Net 2 05-20-2004 04:32 PM



Advertisments