ExcelApp := CreateOleObject( 'Excel.Application' );
用opendialog选择要打开的文件
ExcelApp.WorkBooks.Open( opendialog1.FileName );退出:
excelapp.quit;
form1.Close;
如果打开过excel正常推出,但是如果在没有打开excel的情况下,执行excelapp.quit自然会出错。怎么来判断excleapp已经执行,即:
 if excelapp.xxx then excelapp.quit;
该如何做,请大虾指教。

解决方案 »

  1.   

    if excelapp is nil then
      ...
    else
     ...
     excelapp.quit
      

  2.   

    if opendialog1.Execute then
     begin
       ExcelApp := CreateOleObject( 'Excel.Application' );
       ExcelApp.WorkBooks.Open( opendialog1.FileName );
       .........
       excelapp.quit;
     end;
     form1.Close; 这样可不可以
      

  3.   

    使用if excelapp=null then excelapp.quit
    form1.close;
    就搞定了
    谢谢诸位