Board index » delphi » Excel 95 vs. Excel 97 with Delphi

Excel 95 vs. Excel 97 with Delphi

The following code works great with Excel 95 but generates a "Member not
found." error using Excel 97.  Anybody know what I'm doing wrong?

{**** Begin code ****}
unit MainForm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
  ComObj, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }

    {*** Public member declarations ***}
    Excel : Variant;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  try
    Excel := CreateOleObject('Excel.Application');
    Excel.WorkBooks.Add;
    Excel.Visible := True;
    Excel.WindowState := -4140;
  except
    MessageDlg('Excel could not be started.', mtError, [mbOK], 0);
  end;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  try
    Excel.Quit;
  except
    MessageDlg('Excel could not be terminated.', mtError, [mbOK], 0);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Excel.Range('A1:A1');
  Excel.Selection.Value := 'Hello world!';
end;

end.

{**** End code ***}

Secondly, I've seen lots of discussion in this group which seems to
indicate that using imported type libraries is much faster that using
variants.  If I import the type library for Excel8 (Excel97?) that I see
in the Import Type Library dialog in Delphi 4, what happens if my app is
installed on a machine where only Excel7 is availble? - - TIA, Del G.

 

Re:Excel 95 vs. Excel 97 with Delphi


Well, don't I feel stupid!  A little experimentation on my part yielded the
answer.  The following line:

  Excel.Range('A1:A1');

Should be:

  Excel.Range['A1:A1'];

And now all is well with Excel95 and Excel 97.

Re:Excel 95 vs. Excel 97 with Delphi


If I may interject...

A visit to www.inprise.com/delphi/papers is worth its bandwidth in gold.

Charlie Calvert has an article there on Excel and Word automation.  Get it,
read it, and file it.

Mark Aitken

Quote
Del Gutierrez wrote:
> Well, don't I feel stupid!  A little experimentation on my part yielded the
> answer.  The following line:

>   Excel.Range('A1:A1');

> Should be:

>   Excel.Range['A1:A1'];

> And now all is well with Excel95 and Excel 97.

Other Threads