unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
OleServer, Excel97, StdCtrls;
type
TForm1 = class(TForm)
ExcelApplication1: TExcelApplication;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(ExcelApplication1.ExecuteExcel4Macro('GET.CELL(42)'));//执行宏
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ExcelApplication1.Connect;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
ExcelApplication1.Disconnect;
end;
end.