在Delphi中:我怎么能检测到一个CreateOleObject('Excel.Application')执行过了?就是说,怎么知道有一个Excel文档被打开了??

解决方案 »

  1.   

    用GetActiveOleObject函数啊!(在ComObj单元中)var
      ExcelObj:OleVariant;
    begin
    try
      ExcelObj:=GetActiveOleObject('Excel.Application');
    Except
      CreateOleObject('Excel.Application');
    end;
      

  2.   

    不好意思,应该是:
    var
      ExcelObj:OleVariant;
    begin
    try
      ExcelObj:=GetActiveOleObject('Excel.Application');
    Except
      ExcelObj:=CreateOleObject('Excel.Application');
    end;
      

  3.   

    判断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的内容. 
    参考一下