Picho,
Here is some sample code that I used in VB.NET for performing a mail merge.
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim wrdMailMerge As Word.MailMerge
Dim strDataFile As String
' Create an instance of Word and make it visible
wrdApp = CType(GetObject("", "Word.Application"), Word.Application)
wrdApp.Visible = True
' Open the template
wrdDoc = wrdApp.Documents.Open(TemplateName, False, True)
wrdMailMerge = wrdDoc.MailMerge
Call wrdMailMerge.OpenDataSource(FileName, 0, False, True)
wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument
wrdMailMerge.Execute(False)
' Close the original form document
wrdDoc.Saved = True
wrdDoc.Close(False)
System.Runtime.InteropServices.Marshal.ReleaseComObject(wrdMailMerge)
wrdMailMerge = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(wrdDoc)
wrdDoc = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(wrdApp)
wrdApp = Nothing
GC.Collect()
"Picho" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi all,
>
> I have a problem automating word (office xp).
> I am trying to create a mailmerge datasource using this code:
>
> object oFieldsVector = (object)fieldsVector;
>
> object oFileName = "doc123";//aDoc.Name;
>
> aDoc.MailMerge.CreateDataSource(ref oFileName, ref missing, ref missing,
ref
> oFieldsVector, ref missing, ref missing, ref missing, ref missing, ref
> missing);
>
> aDoc.MailMerge.EditDataSource();
>
> Word.Document aTable = WordApp.ActiveDocument;
>
> Word.Table table = aTable.Tables.Item(1);
>
> for (int j=1;j<dataSource.Rows.Count;j++)
>
> {
>
> table.Select();
>
> table.Rows.Add(ref missing);
>
> }
>
>
>
> the problem is that when i get to the row adding part, a dialog opens up
in
> the word application asking something about the columns.
>
> this issue never came up in all MS and others examples on the web.
>
> did anyone see this too?
>
> what am i doing wrong? (this is actually almost coppied from MSDN sample).
>
>
>
> thanx,
>
>
>
> Picho
>
>
|