Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MS Word , MailMerge and C#
Message
De
11/03/2005 19:18:54
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00994745
Message ID:
00995078
Vues:
27
Gerard,

As I said, I'm no expert ... but, in comparing your posted code to what I can figure out from our code, I notice a difference with the following few lines:
oWord.ActiveDocument.MailMerge.Destination = 0;
oWord.ActiveDocument.MailMerge.Execute(ref oFalse);
Our code does this instead:
object Pause = 20000;
oWord.ActiveDocument.MailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument;
oWord.ActiveDocument.MailMerge.Execute(ref Pause);
I'm not sure if that's all that's wrong with your code, but try that and see if it helps.

~~Bonnie



>Hi Bonnie
>Code is as follows:
>// Create a Text file to do MailMerge
>StreamWriter StrWriter = File.CreateText(@"K:\MYFOL\MAILMERG.TXT");
>StrWriter.WriteLine("isr_salut,isr_fname,isr_lname,isr_coname,isr_ad1,isr_ad2,isr_ad3,isr_ad4,is  r_ad5");
>StrWriter.WriteLine("Mr.,Joe,Bloggs,Kernel   Software,U6,Bridgecourt,Walkinstown Ave,walkinstown,Dublin,Ireland");
>			StrWriter.Close();
>			
>oName = @"K:\MYFOL\MAILMERG.DOC";
>oWord.Documents.Open(ref oName, ref oMissing,
>                 ref oMissing, ref oMissing, ref oMissing, ref oMissing,
>		 ref oMissing, ref oMissing, ref oMissing, ref oMissing,
>        	 ref oMissing, ref oMissing, ref oMissing, ref oMissing,
>		 ref oMissing, ref oMissing);
>
>oFormLetter = oWord.ActiveDocument;
>oWord.ActiveDocument.MailMerge.Destination = 0;
>// gives read only message
>//oWord.ActiveDocument.MailMerge.DataSource.Name = "MAILMERG.TXT";
>			
>
>// oWord.ActiveDocument.MailMerge.DataSource.FirstRecord = 1;
>//oWord.ActiveDocument.MailMerge.DataSource.LastRecord = -16;
>oWord.ActiveDocument.MailMerge.Execute(ref oFalse);
>
>Following is happening:
>
>On the DataSource.Name line I was getting a Read Only Control, so I amended the doc file and inserted the link into the mail merge doc file itself
>(This works fine if I go into Word and run the merge fro there)
>
>I was getting errors with the First and Last record so I commented them
>It is also giving an error with the execute line, which I assume is the line that 'Does' the mailmerge
>
>Regards,
>Gerard
>
>
>
>
>
>>Gerard,
>>
>>How about a link to the demo you're talking about? Or, better yet, post your code. We've got MailMerge working with C#. I wasn't the one who wrote the code though, so I'm no expert, but I might be able to look at your code and see what the problem is.
>>
>>~~Bonnie
>>
>>
>>
>>>Hi.
>>>I have been trying to get Mailmerge automation up with c #.
>>>I've got it to the stage where it loads up Word, and opens the document.
>>>Howeverwhen I run the Execute method ,as follows:
>>>
>>>oWord.ActiveDocument.MailMerge.Execute(ref oFalse);
>>>
>>>I get a .com exception error.
>>>
>>>(I use same format as per demo on MS site)
>>>
>>>Wondering if anybody here has got Mailmerge working with c#
>>>
>>>Regards,
>>>Gerard
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform