exceldelphipascallazarusole-automation

Opening an Excel spreadsheet by making Excel an OLE object


I have tried using the following code to open a spreadsheet I have created in Excel. It runs, but a popup keeps coming up saying that my file has been deleted or moved. The file definitely still exists. I have tried creating new files with other names. none of them work.

procedure TForm1.Button1Click(Sender: TObject);
var
  Excelfile: Variant;
  Workbook: Variant;
begin
  Excelfile := CreateOleObject('Excel.Application');
  Workbook := Excelfile.workbooks.open('filename.xls');
end;

Solution

  • You should use a fully-qualified (absolute) path, not a relative path.

    (Indeed, if I'd ask you to go to the red cottage in Sweden, you'd certainly ask me about the precise address.)