Information générale
Titre:
Word automation question
Hi,
I am trying to automate a mailmerge using VFP6 and Word2000.
Things (almost) work as planned. I am stuck with a problem of controlling WHERE insertions happen in a table. I have looked for some documentation for Tables[].Rows[] but couldn't find anything I could use.
The problem is that I can get one of 2 results:
1- the 1st row is actually inserted into the column titles making the whole merge unusable
2- if I force an Add() at the beginning, all rows are inserted properly except I am left with the 1st row BLANK. How can I specifically delete a row ?
Can anyone point me to a useful description of the few calls I need (sourcedoc, tables, rows, etc...) ?
Thanks
Henry
The code follows:
================================================
* Create an instance of Word.
This.oWord = CreateObject("Word.Application")
* Word 2000 detaches connection if datasource not found
If File(goapp.cMMHeader+[.doc])
Erase (goapp.cMMHeader+[.doc])
Endif
* Create a document object
This.oDocument = This.oWord.Documents.Open(goapp.cMMDocument)
Local loSourceDoc, loRow, loTable
Select (goapp.cMMCursor)
With This.oDocument.MailMerge
* Attach the data to the document
.CreateDataSource(goapp.cMMHeader, , , goapp.cMMFieldList)
.EditDataSource
loSourceDoc = This.oWord.ActiveDocument
loTable = loSourceDoc.Tables[1]
loRow = loTable.Rows[1]
* loRow = loTable.Rows.Add()
* Now open the data source and put the data into the document
Scan
*For clarity, assume all fields are of type 'C'
For I = 1 To Occurs([,],goapp.cMMFieldList)+1
loRow.Cells[ I ].Range.InsertAfter(Trim( Eval(Fields( I ))))
EndFor
loRow = loTable.Rows.Add()
EndScan
loRow.Delete()
loSourceDoc.Save()
EndWith
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement