用GetActiveOleObject函数啊!(在ComObj单元中)var ExcelObj:OleVariant; begin try ExcelObj:=GetActiveOleObject('Excel.Application'); Except CreateOleObject('Excel.Application'); end;
不好意思,应该是: var ExcelObj:OleVariant; begin try ExcelObj:=GetActiveOleObject('Excel.Application'); Except ExcelObj:=CreateOleObject('Excel.Application'); end;
判断Word是否运行先在Form上添加一个Server组件中的WordApplication,命名为WordApplication1,然后在"关闭WORD"按扭中输入如下代码: var SaveChanges, OriginalFormat, RouteDocument: OleVariant; begin SaveChanges := WdDoNotSaveChanges; OriginalFormat := UnAssigned; RouteDocument := UnAssigned; try WordApplication1.Quit(SaveChanges, OriginalFormat, RouteDocument); WordApplication1.Disconnect; except on E: Exception do begin Showmessage(E.Message); WordApplication1.Disconnect; end; end; end; 准成,当然了,请按实际情况修改 SaveChanges, OriginalFormat, RouteDocument的内容. 参考一下
ExcelObj:OleVariant;
begin
try
ExcelObj:=GetActiveOleObject('Excel.Application');
Except
CreateOleObject('Excel.Application');
end;
var
ExcelObj:OleVariant;
begin
try
ExcelObj:=GetActiveOleObject('Excel.Application');
Except
ExcelObj:=CreateOleObject('Excel.Application');
end;
var
SaveChanges, OriginalFormat, RouteDocument: OleVariant;
begin
SaveChanges := WdDoNotSaveChanges;
OriginalFormat := UnAssigned;
RouteDocument := UnAssigned;
try
WordApplication1.Quit(SaveChanges, OriginalFormat, RouteDocument);
WordApplication1.Disconnect;
except
on E: Exception do
begin
Showmessage(E.Message);
WordApplication1.Disconnect;
end;
end;
end;
准成,当然了,请按实际情况修改 SaveChanges, OriginalFormat, RouteDocument的内容.
参考一下