Board index » delphi » Problems with Excel OLE Automation

Problems with Excel OLE Automation

Hi

How do I automate Excel from Delphi. I've tried the following;

procedure TFormMain.ExcelOLETest;
var
  MSExcel : Variant;
begin
  MSExcel := CreateOLEObject('Excel.Application');

  MSExcel.Visible := TRUE;      // This works fine
  MSExcel.FileNewStandard;      // DOES NOT WORK. I GET AN EXCEPTION ERROR
end;

Can someone give me a full examlpe how I interface with Excel. May I write
directly to cells? My goal is to export numbers in a StringGrid to a Excel
sheet.

Is it possible to Automate Excel thru OLE2 without starting Excel first?

Please help me out!!!!

Thanks in advance!

Ove Ranheim
o...@nvg.ntnu.no

 

Re:Problems with Excel OLE Automation


Hi:

  I don't have a full answer to your question; but
as far as I can tell there is no 'FileNewStandard'
method of the Excel Application object.
See (if you have it) VBA_XL.HLP (I have MSOFFICE and
it's in my MSOFFICE\EXCEL directory).

I think you need something like:

MSExcel.Workbooks.Add;

Anyway, this might point you in the right direction.
Also, the book Delphi2 Unleashed has (If I recall
correctly), an example of pasting directly to an Excel
spreadsheet.

Quote
o...@nvg.ntnu.no (Ove Ranheim) wrote:
>Hi
>How do I automate Excel from Delphi. I've tried the following;
>procedure TFormMain.ExcelOLETest;
>var
>  MSExcel : Variant;
>begin
>  MSExcel := CreateOLEObject('Excel.Application');
>  MSExcel.Visible := TRUE;      // This works fine
>  MSExcel.FileNewStandard;  // DOES NOT WORK. I GET AN EXCEPTION ERROR
>end;

>Can someone give me a full examlpe how I interface with Excel. May I write
>directly to cells? My goal is to export numbers in a StringGrid to a Excel
>sheet.
>Is it possible to Automate Excel thru OLE2 without starting Excel first?
>Please help me out!!!!
>Thanks in advance!
>Ove Ranheim
>o...@nvg.ntnu.no

-------------------------------------------------------------------------------
Anything I have said or will ever say are my own opinions and not necessarily
those of my company.

Michael J. Loeffler
Teletrade, Inc.

mloeff...@teletrade.com
-------------------------------------------------------------------------------

Other Threads