Delphi8でExcelのRangeのEndプロパティを使うには?


KENT  2004-09-18 01:21:51  No: 10986

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;


※返信する前に利用規約をご確認ください。

※Google reCAPTCHA認証からCloudflare Turnstile認証へ変更しました。






  このエントリーをはてなブックマークに追加