我看看了一下呢的事件OFFICE参考没有,不过。
我试了一下,这个属性和excelapp.onwindowsactive差不多。
这是我测试的代码,你改改,就应该是了。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Excel2000, OleServer, Buttons, Word2000;
type
TForm1 = class(TForm)
Excel2000: TExcelApplication;
Button1: TButton;
OD: TOpenDialog;
Memo1: TMemo;
ExcelWorkbook1: TExcelWorkbook;
BitBtn1: TBitBtn;
WordApp: TWordApplication;
WordDocument1: TWordDocument;
procedure Button1Click(Sender: TObject);
procedure Excel2000SheetChange(Sender: TObject; var Sh,
Target: OleVariant);
procedure Excel2000WorkbookOpen(Sender: TObject; var Wb: OleVariant);
procedure Excel2000WorkbookBeforeClose(Sender: TObject; var Wb,
Cancel: OleVariant);
procedure BitBtn1Click(Sender: TObject);
procedure WordAppDocumentChange(Sender: TObject);
procedure WordAppDocumentBeforeClose(Sender: TObject; var Doc,
Cancel: OleVariant);
procedure Excel2000WorkbookActivate(Sender: TObject;
var Wb: OleVariant);
procedure Excel2000WorkbookDeactivate(Sender: TObject;
var Wb: OleVariant);
private
{ Private declarations }
FCurWook:_Workbook;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Intf:_Workbook;
begin
if OD.Execute then
begin
Excel2000.Disconnect;
Excel2000.Connect;
Intf:=Excel2000.Workbooks.Open(OD.FileName,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,0)
as _WorkBook;
ExcelWorkbook1.ConnectTo(Intf);
if FCurWook<>Intf then
begin
Memo1.Lines.Add('Workbook changeed');
FCurWook:=Intf;
end;
Excel2000.Visible[0]:=True;
end;
end;
procedure TForm1.Excel2000SheetChange(Sender: TObject; var Sh,
Target: OleVariant);
begin
Memo1.Lines.Add('Sheet change');
end;
procedure TForm1.Excel2000WorkbookOpen(Sender: TObject;
var Wb: OleVariant);
begin
Memo1.Lines.Add('WorkBook Open');
end;
procedure TForm1.Excel2000WorkbookBeforeClose(Sender: TObject; var Wb,
Cancel: OleVariant);
begin
Memo1.Lines.Add('Workbook Close Before');
//ShowMessage('ok');
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
FFileName:OleVariant;
begin
IF OD.Execute THEN
BEGIN
WordApp.Disconnect;
WordApp.Connect;
FFileName:=OD.FileName;
WordApp.Documents.OpenOld(FFileName,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,EmptyParam);
WordApp.Visible:=True;
WordApp.ShowMe;
END;
end;
procedure TForm1.WordAppDocumentChange(Sender: TObject);
begin
Memo1.Lines.Add('word change ');
end;
procedure TForm1.WordAppDocumentBeforeClose(Sender: TObject; var Doc,
Cancel: OleVariant);
begin
Memo1.Lines.Add('word before');
end;
procedure TForm1.Excel2000WorkbookActivate(Sender: TObject;
var Wb: OleVariant);
var
intf:_Workbook;
begin
Memo1.Lines.Add('WorkBook changed....');
if intf<>FCurWook then
begin
FCurWook:=intf;
Memo1.Lines.Add('WorkBook changed');
end;
end;
procedure TForm1.Excel2000WorkbookDeactivate(Sender: TObject;
var Wb: OleVariant);
var
intf:_Workbook;
begin
if intf<>FCurWook then
begin
FCurWook:=intf;
Memo1.Lines.Add('WorkBook changed');
end;
end;
end.
不过有一个地方,就是记录当前的EXCEL,感觉使用指针好呢,要不这个_workbook怎么比较呢 ,比较文档还是标题?