Hi,
For grizzled veterans, this may be a very trivial question but I am having problems working on Ranges and Cells on Excel.Interop.
Basically, I have the following code:
FileName := 'C:\Book1.xlsx';
XlApp := XlApp.ApplicationClass;
XlWrkBk := XlApp.Workbooks.Open(FileName,0,TRUE,5,'','',TRUE,2,'\t',FALSE,FALSE,0,TRUE,1,0);
XlWrkSht := XlWrkBk.Sheets.Item(1);
XlRange := XlWrkSht.Range('A1','A10');
How do I work with the cells in the defined XlRange? I searched for it a lot but I could not seem to find the correct syntax. I tried the following:
XlWrkSht.Cells(3,1).Value2 := 'ABCDE';
XlRange.Cells(1,1).Value2 := 'XXXXX';
XlRange.Cells[1,1].Value2 := 'XXXXX';
And I get a "parameter 0" error or a "too many dimensions" error. I understand the errors but for the life of me, I do not know how else to manipulate the cells within a range. Any help is greatly appreciated.
Answers
Anyway, I can write data to specific cells using:
But it seems inefficient as I have to create XlRange each time I access a new cell. I was thinking of defining XlRange for multiple cells and just loop through it using CELLS but like I said, I cannot get the write syntax for it.
xStepa
Thanks for taking the time but I have already tried that and I get the error that