Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
MS Word , MailMerge and C#
Message
 
To
11/03/2005 09:49:05
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00994745
Message ID:
00994965
Views:
20
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform