View Single Post
  #7   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Cindy M -WordMVP- Cindy M  -WordMVP- is offline
external usenet poster
 
Posts: 370
Default C# MailMerge from Excel

Hi ?B?Y2hyaXM=?=,

OK, my code executes with no errors, and it doesn't hang, but nothing 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$`";

",re f 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.

Comment everything after this point, make sure the Word app is visible 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 :-)