save word after mail merge

Discussion in 'ASP .Net' started by =?Utf-8?B?QmFkaXM=?=, Apr 5, 2007.

  1. 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.
    =?Utf-8?B?QmFkaXM=?=, Apr 5, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?QmFkaXM=?=

    Ben Rush Guest

    I think you're in the wrong newsgroup.

    Try microsoft.public.office.*

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


    "Badis" <> wrote in message
    news:...
    > 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.
    >
    Ben Rush, Apr 5, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VB Programmer

    How to emulate Word mail merge in HTML?

    VB Programmer, May 20, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,126
    VB Programmer
    May 20, 2004
  2. Martin Feuersteiner
    Replies:
    0
    Views:
    2,971
    Martin Feuersteiner
    Jul 19, 2004
  3. Steve M

    MS Word mail merge automation

    Steve M, Sep 30, 2005, in forum: Python
    Replies:
    2
    Views:
    1,297
    Steve M
    Oct 5, 2005
  4. Replies:
    0
    Views:
    417
  5. Jos

    Using a webservice for mail merge in Word

    Jos, Aug 28, 2003, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    166
    Matthew Holton
    Aug 30, 2003
Loading...

Share This Page