Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Automation question (MS Word from VFP)
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Automation question (MS Word from VFP)
Miscellaneous
Thread ID:
01144904
Message ID:
01144904
Views:
85
I'm using automation to open an existing MS Word file from VFP 9, create an MS Word table, then insert some records from a VFP table into the cells of the Word table.

Example:
USE SomeVFPTable
SELECT SomeVFPTable
nTotRecords = RECCOUNT()

oWord = CREATEOBJECT("Word.Application")
oDocument = oWord.Documents.OPEN("C:\test.doc")

oRange = oWord.ActiveDocument.RANGE(0,0)
oRange.SELECT
oTable = oDocument.TABLES.ADD(oRange,nTotRecords,2)

nCounter = 1
SCAN
   oTable.Cell(nCounter,1).RANGE.InsertAfter(SomeVFPTable.SomeVFPField)
   oTable.Cell(nCounter,2).RANGE.InsertAfter(SomeVFPTable.SomeVFPField2)
   nCounter = nCounter + 1
ENDSCAN
All of this works well, but in some circumstances, I need to insert a second MS Word table below the original table.

Since the length of the original MS Word table varies (depending on the number of records), how do I determine where to create the second MS Word table? Since the first one is positioned at the top of the page, it's not an issue, as in:
oRange = oWord.ActiveDocument.RANGE(0,0)
oRange.SELECT
How would I position the cursor one line below the last record of the first MS Word table? I've tried using the value of nCounter (from above) once the first MS Word table has been created, but no matter what I do, the second MS Word table always ends up being created in Cell 1,1 of the first MS Word table.

Thanks,
Next
Reply
Map
View

Click here to load this message in the networking platform