When using Excel as an ActiveX server, why does the excel.exe process still exist after I close Excel?

40 views (last 30 days)
When using Excel as an ActiveX server, I would like to know why the excel.exe process still exists after I close Excel.
I would like to know how the lingering Excel process that was created with actxserver can be terminated.
The following code uses ActiveX to open Excel, set values to a range, and close Excel. However, if I look under my Task Manager --> Processes, it still show that EXCEL.EXE exists. It is not taking any CPU time, but it is taking up memory.
Excel = actxserver('Excel.Application');
set(Excel, 'Visible', 1);
Workbooks = Excel.Workbooks;
Workbook = invoke(Workbooks, 'Add');
Sheets = Excel.ActiveWorkBook.Sheets;
sheet2 = get(Sheets, 'Item', 2);
invoke(sheet2, 'Activate');
Activesheet = Excel.Activesheet;
A = [1 2; 3 4];
ActivesheetRange = get(Activesheet,'Range','A1:B2');
set(ActivesheetRange, 'Value', A);
Range = get(Activesheet, 'Range', 'A1:B2');
B = Range.value;
B = reshape([B{:}], size(B));
invoke(Workbook, 'SaveAs', 'myfile.xls');
invoke(Excel, 'Quit');

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 11 Mar 2010
To shut down Excel, which is the ActiveX server in this case, execute the RELEASE command with the ActiveX server object and all the interface handles. Note that all interface handles to the server object must be released in order for the server process to terminate.
For the code under 'Problem Description', following are the interface handles (in order of creation):
Workbooks
Workbook
Sheets
sheet2
Activesheet
ActivesheetRange
Range
The following lines of code must be appended to the original code in order for the Excel automation server process to terminate:
release(Range)
release(ActivesheetRange)
release(Activesheet)
release(sheet2)
release(Sheets)
release(Workbook)
release(Workbooks)
release(Excel)

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!