Excel and Delphi5 Enterprise

Dear  All

I wish to be able to open an  excel file in delphi string grid by opening it
with and opendialog component.

I modified some sample code I got from the Borland  community

Here tis

procedure TForm2.Open1Click(Sender: TObject);
begin
      PlanetaryCoOrdOpenDialog.Execute;
      Label1.Caption := GetCurrentDir;
      Namefile :=(PlanetaryCoOrdOpenDialog.FileName);
end;

procedure TForm2.PlanetaryCoOrdOpenDialog1Close(Sender: TObject);
var
WorkBk : _WorkBook;
WorkSheet : _WorkSheet;
K, R, X, Y : Integer;
IIndex : OleVariant;
RangeMatrix : Variant;
NomFich : WideString;
Namefile: String;
begin
NomFich := (GetCurrentDir) + '\' + (Namefile);
IIndex := 1;
XLApp.Connect;
// Open the Excel File
XLApp.WorkBooks.Open(NomFich,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,0);
WorkBk := XLApp.WorkBooks.Item[IIndex];
WorkSheet := WorkBk.WorkSheets.Get_Item(1) as _WorkSheet;
// In order to know the dimension of the WorkSheet, i.e the number of rows
and the
// number of columns, we activate the last non-empty cell of it
WorkSheet.Cells.SpecialCells(xlCellTypeLastCell,EmptyParam).Activate;
// Get the value of the last row
X := XLApp.ActiveCell.Row;
// Get the value of the last column
Y := XLApp.ActiveCell.Column;
// Define the number of the columns in the TStringGrid
  GenericStringGrid.ColCount := Y;
// Assign the Variant associated with the WorkSheet to the Delphi Variant
Matrix
  RangeMatrix := XLApp.Range['A1',XLApp.Cells.Item[X,Y]].Value;
// Quit Excel and Disconnect the Server
  XLApp.Quit;
  XLApp.Disconnect;
//  Define the loop for filling in the TStringGrid
  K := 1;
  repeat
    for R := 1 to Y do
      GenericStringGrid.Cells[(R - 1),(K - 1)] := RangeMatrix[K,R];
    Inc(K,1);
    GenericStringGrid.RowCount := K + 1;
  until
   K > X;
// Unassign the Delphi Variant Matrix
   RangeMatrix := Unassigned;
end;

I get an ole exception error.
I have tried  to type in the filepath with something  like

NomFich := 'c:\mydocuments\example.xls'  and alas it works

Any ideas  would be appreciated.

Thanks to the original author for the above.

David