Re: C# MailMerge from Excel
- From: "Peter Jamieson" <pjj@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 2 Aug 2006 17:36:30 +0100
When you've finsihed with the Word object and released oWordDoc etc, you'll
need something like
oWordApp.Quit
Peter Jamieson
"chris" <chris@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5DC067F7-6635-418C-BC80-89819DAFED07@xxxxxxxxxxxxxxxx
Thank you! I got it to work like this:
wrdMailMerge.Destination =
Word.WdMailMergeDestination.wdSendToNewDocument;
wrdMailMerge.Execute(ref missing);
object oTemplateDone = @"C:\test\done.doc";
oWordApp.ActiveDocument.SaveAs(ref oTemplateDone,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);
After the merge is done I still have WINWORD.EXE running under aspnet. I
know that GC is supposed to take care of that, but I have it in memory for
a
long period of time. I tried to release them like this:
// Unload objects from the memory
System.Runtime.InteropServices.Marshal.ReleaseComObject (wrdMailMerge);
System.Runtime.InteropServices.Marshal.ReleaseComObject (oWordApp);
System.Runtime.InteropServices.Marshal.ReleaseComObject (oWordDoc);
or like this:
wrdMailMerge = null;
oWordDoc = null;
oWordApp = null;
but none of those ways worked. any tricks?
Thanks!
"Cindy M -WordMVP-" wrote:
Hi =?Utf-8?B?Y2hyaXM=?=,
OK, my code executes with no errors, and it doesn't hang, but nothingComment everything after this point, make sure the Word app is visible
really
happens.
object oConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\test\\list.xls;Mode=Read;Extended
Properties=\"HDR=YES;IMEX=1;\";Jet OLEDB:Engine Type=35;";
object oQuery = "SELECT * FROM `Sheet1$`";
wrdMailMerge.OpenDataSource(@"C:\test\list.xls",ref oFormat,ref oFalse,
ref
oFalse, ref oTrue,ref oFalse, ref missing, ref missing,ref oFalse, ref
missing, ref missing,ref oConn, ref oQuery, ref missing, ref
missing,ref
oSubType);
the code runs with the connection you told me, but I am not sure it is
reading from the file.
and
activated. Display the mail merge toolbar and see if any besides the
first two
buttons are available. Are you able to see the list of fields, for
example? Or
to preview the data (the <<ABC>> button)?
To answer your question: the new document is generated only in memory and
should have become the ActiveDocument. It's not saved to disk. If you
aren't
seeing it, then Execute is apparently not running. Try passing an object
that's
set to false (object ofalse = false; wrdMailmerge.Execute(ref ofalse);)
and see
if that makes any difference.
after I call OpenDataSource() I do this:
wrdMailMerge.Destination =
Word.WdMailMergeDestination.wdSendToNewDocument;
wrdMailMerge.Execute(ref missing);
the enum WdMailMergeDestination.wdSendToNewDocument sends the merge doc
to a
new file. where is that doc generated? in the same directory?
Since nothing happened, I tried saving it:
object oTemplateDone = @"C:\test\done.doc";
oWordDoc.SaveAs(ref oTemplateDone,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);
The doc is saved as done.doc with the merge fields not populated.
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or
reply
in the newsgroup and not by e-mail :-)
.
- References:
- Re: C# MailMerge from Excel
- From: Peter Jamieson
- Re: C# MailMerge from Excel
- From: chris
- Re: C# MailMerge from Excel
- From: Peter Jamieson
- Re: C# MailMerge from Excel
- From: chris
- Re: C# MailMerge from Excel
- From: Cindy M -WordMVP-
- Re: C# MailMerge from Excel
- From: chris
- Re: C# MailMerge from Excel
- Prev by Date: Re: C# MailMerge from Excel
- Next by Date: Re: Can't get Word 2003 to keep data file with mail merge main documen
- Previous by thread: Re: C# MailMerge from Excel
- Next by thread: Re: C# MailMerge from Excel
- Index(es):
Relevant Pages
|