Delphi8でExcel操作をする処理で、特定の列の最後の行を取得するために、RangeオブジェクトのEndプロパティを使用するとコンパイル時に下記のエラーが発生してしまいます。どなたか回避方法をご存知ないでしょうか?
[エラー] unitMain.pas(230): 識別子 が必要な場所に 'END' があります
【参考ソース】
function Xls(fnm);
var
j,maxRow: integer;
ExcelApp : Excel._Application;
ExcelWorkBook : Excel._Workbook;
ExcelSheets : Excel.sheets;
ExcelSheet : Excel._Worksheet;
begin
ExcelApp := Excel.ApplicationClass.Create;
ExcelWorkBook := ExcelApp.Workbooks.Open(fnm, Missing.Value,Missing.Value,
Missing.Value,Missing.Value,Missing.Value,
Missing.Value,Missing.Value,Missing.Value,
Missing.Value,Missing.Value,Missing.Value,
Missing.Value);
ExcelSheets := ExcelWorkBook.sheets;
try
for j:=1 to ExcelSheets.Count do begin
ExcelSheet := ExcelSheets[TObject(j)];
ExcelSheet.Activate;
//A列の最後の行を取得
//(EndプロパティがDelphi8はコンパイルエラーになってしまう・・・)
maxRow := ExcelSheet.Range[TObject('A65535'), Missing.Value].End[Excel.XlDirection.xlUp].Row;
end;
ExcelWorkBook.Saved := True;
finally
ExcelApp.Quit;
ExcelApp := unAssigned;
ExcelWorkBook := unAssigned;
ExcelSheets := unAssigned;
ExcelSheet := unAssigned;
end;
end;
ツイート | ![]() |