473,382 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

save word after mail merge

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.

Apr 5 '07 #1
1 2102
I think you're in the wrong newsgroup.

Try microsoft.public.office.*

--
~~~~~~~~~~~
Ben Rush
http://www.ben-rush.net/blog
"Badis" <Ba***@discussions.microsoft.comwrote in message
news:0D**********************************@microsof t.com...
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.

Apr 5 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Colin Halliday | last post by:
I have a Word 2003 mail merge main document (form letter) that is linked to another Word document data source for the mail merge. If I open this doc using the Word GUI, it first asks me to...
8
by: Ron B | last post by:
Help!!! What am I doing wrong? I am working with Office 2003 and am trying to create a command button on an Access form that will create a mail merge in Word from an Access table. I want to...
6
by: crealesmith | last post by:
Firstly, I have no problem with mail merging to Word, VB code for that works perfectly. On one mail merge I need to merge 15 fields of data that are from 3 seperate records. The 3 records are all...
7
by: =?Utf-8?B?QmFkaXM=?= | last post by:
Hi, I'm trying to follow a mail merging example in C#.Net that I got from: http://support.microsoft.com/default.aspx/kb/301659 and in one the methods: Word.Application wrdApp; Word._Document...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.