>Hello All,
>I'm trying out an Excel example from the book "Microsoft Office Automation with Visual Foxpro" , the example in question "Scans" a table, populates a couple of columns and moves down a row ( in the worksheet ) using the Range.Offset method, however when I look at the output spreadsheet there is only one row populated which contains data from the last record, indicating the Offset method is not working, any ideas as to why this is?
>
>my code snippet
>I've left all the object creation code out for brevity
>
>
>oRange = .Range("A12:C12")
>
>scan
> .Columns[1].Value = myfieldata1
> .Columns[2].Value = myfieldata2
> .Columns[3].Value = myfieldata3
> oRange = oRange.Offset(1,0)
>endscan
>
>
>
>The fist iteration is fine but subsequent ones are overwriting the previous values, I'm using VFP 7.0. and Office 97 on Win XP pro, any help much appreciated
>
>regards
>
>Pete Kane
Pete,
I think you cut more than needed for brevity :) I bet your code is similar to :
oRange = .Range("A12:C12")
with oRange
scan
.Columns[1].Value = myfieldata1
.Columns[2].Value = myfieldata2
.Columns[3].Value = myfieldata3
oRange = oRange.Offset(1,0)
endscan
endwith
Or worse with has a higher level object.
If that's the case remember oRange setting in loop has no effect. With would grab the first reference and repeatedly values in them would be changed in scan..endscan leaving you with the last record.
Prefix the .Columns with oRange. ie:
Use Data\customer
oExcel = Createobject('Excel.Application')
With oExcel
.Workbooks.Add
.Visible = .T.
With .ActiveWorkbook.ActiveSheet
oRange = .Range("A12:C12")
Scan
oRange.Columns[1].Value = cust_id
oRange.Columns[2].Value = company
oRange.Columns[3].Value = Title
oRange = oRange.Offset(1,0)
Endscan
Endwith
Endwith
PS: I think this is only for sampling Range.Offsett, otherwise setting cell by cell in excel is slow.
Cetin