using Microsoft Word Mail Merge in C# Win Form App.

J

JW

I pasted an example C# mail merge code from microsoft
website(http://support.microsoft.com/?kbid=301659)
concerning Mail Merge and placed on a form as the
direction requested. I also referenced the COM form
Microsoft Word Object Library. When I build this project
I get the following error:

C:\NET Projects\Mail Merge\MailMerge\Form1.cs(108):
Cannot apply indexing with [] to an expression of
type 'Word.Tables'


The error occurs at the following code:

private void FillRow(Word._Document oDoc,
int Row, string Text1,
string Text2, string Text3,
string Text4)
{
// Insert the data into the
specific cell.
oDoc.Tables[1].Cell
(Row,1).Range.InsertAfter(Text1);
oDoc.Tables[1].Cell
(Row,2).Range.InsertAfter(Text2);
oDoc.Tables[1].Cell
(Row,3).Range.InsertAfter(Text3);
oDoc.Tables[1].Cell
(Row,4).Range.InsertAfter(Text4);
}


Am I forgetting to reference something else. Please
help. Fustrated C# programmer.
 
J

Jochen Stuempfig

JW said:
I pasted an example C# mail merge code from microsoft
website(http://support.microsoft.com/?kbid=301659)
concerning Mail Merge and placed on a form as the
direction requested. I also referenced the COM form
Microsoft Word Object Library. When I build this project
I get the following error:

C:\NET Projects\Mail Merge\MailMerge\Form1.cs(108):
Cannot apply indexing with [] to an expression of
type 'Word.Tables'


The error occurs at the following code:

private void FillRow(Word._Document oDoc,
int Row, string Text1,
string Text2, string Text3,
string Text4)
{
// Insert the data into the
specific cell.
oDoc.Tables[1].Cell
(Row,1).Range.InsertAfter(Text1);
oDoc.Tables[1].Cell
(Row,2).Range.InsertAfter(Text2);
oDoc.Tables[1].Cell
(Row,3).Range.InsertAfter(Text3);
oDoc.Tables[1].Cell
(Row,4).Range.InsertAfter(Text4);
}


Am I forgetting to reference something else. Please
help. Fustrated C# programmer.


Hello,

i tried the example also. You have to replace the following line

Object oHeader = "FirstName, LastName, Address, CityStateZip";

through

Object oHeader = "FirstName; LastName; Address; CityStateZip";

greetings

Jochen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top