03-14-2011 12:40 AM
I am using Excel Report Instrument functions for creating excel application and sheet,workbook after reading/writing in to excel file am closing all the handles using CA_DiscardObjHandle (handle); even after file is getting closed m checking it in TaskManager then one EXCEl.EXE process is keep running there,pls let me know how to deal with this....
Solved! Go to Solution.
03-15-2011 07:10 AM
Hi Ajoy,
I dont know the CVI funtion. But you can do this using TaskKill function in command prompt
open the command prompt and try the following command
c:\>taskkill /f /im excel.exe
Thanks and Regards
NB
03-15-2011 08:18 AM
A Kumar:
Have you tried running the example program excelreportdemo.prj that ships with CVI? It ends the excel process by discarding multiple handles, and it works even if you're editing a cell or have an Excel dialog open, etc. Try running this without modification and verify that the excel process is closed when you quit the CVI app.
Here's the Quit function from excelreportdemo. It checks for and closes handles for the worksheet, chart, workbook, and excel application.
int CVICALLBACK Quit (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
if (worksheetHandle)
CA_DiscardObjHandle(worksheetHandle);
if (chartHandle)
CA_DiscardObjHandle(chartHandle);
if (workbookHandle)
{
ExcelRpt_WorkbookClose(workbookHandle, 0);
CA_DiscardObjHandle(workbookHandle);
}
if (applicationHandle)
{
ExcelRpt_ApplicationQuit(applicationHandle);
CA_DiscardObjHandle(applicationHandle);
}
QuitUserInterface (0);
break;
}
return 0;
}
03-15-2011 11:25 PM - edited 03-15-2011 11:26 PM
Hi Nagraj,
Thanks for ur reply. No I wanted to kill it from my CVI application, pls let me know if u have any idea
03-15-2011 11:33 PM
Hi AI S,
I have tried with this , but it works for one case i.e. if I am opening and simply closing the excel without doing any operation on the file its killing the excel.exe process fine. But If I am doing any operation on excel after opening it, like read/write etc then am closing the file & clearing handles using same CA_DiscardObjHandle() its not killing the excel.exe process. I am not getting why its not able to kill the process after doing some manipulation on it?
03-16-2011 07:52 AM
excelreportdemo manipulates the file: after opening Excel, it writes data, formats cells, adds calculations, adds a graph, and lets you manipulate that graph. After doing all those actions, I also manually my some edits to the spreadsheet. After all that, I still have no problem quitting Excel.
Using the unmodified excelreportdemo, were you able to do anything in excel to force excel stay open?
Are you calling ExcelRpt_WorkbookClose() and ExcelRpt_ApplicationQuit() in addition to discarding the handles? You need to do both, not just discard the handles. See the code I posted from the excelreportdemo example.
Have you checked to see if you get any errors discarding the handles?
Are you sure that you are passing the correct handle to CA_DiscardObjHandle()?
03-16-2011 08:56 PM
Hi! Kumar,
You probably add new objects and object handles when modifying the example codes.
I had similar issue before, and the reason is the added objects are not discarded (cleaned up) properly when terminating the program. Once you clean them up, the EXCEL.EXE will disapear.
03-17-2011 08:53 AM
Hey Kumar -
I've helped a number of people debug this exact issue, and it has almost always turned out to be exactly what dcl9000 has said. If you are using LabWindows/CVI 9.0 or later, the fastest way to find this out is to enable resource tracking (Options>Build Options>Debugging Level>Extended), and then run your program start to finish. The resource tracking window will display after your program completes normally if you have resources you have not disposed of, such as Excel automation handles. Take a look at this documentation for more information.
NickB
National Instruments
03-18-2011 03:37 AM
Yes AI,
M closing the workbook & quiting the application using same functions as you mentioned.....one reason might be as DCl has posted...I will try to track all the handles and will see wat is happening.................meanwhile if you have any suggestions pls keep posting..
Thanks
03-18-2011 11:39 AM
Not sure what version of Excel you are using, but I have an application using Excel that works fine with Excel 2003 but leaves the Excel process running when using Excel 2007.