Title: Closing Excel ActiveX object from JavaScript leaves excel.exe in memory
Tags: javascript;html;excel;activex
Question: function gbid(s) {
return document.getElementById(s);
function GetData(cell,row) {
var excel = new ActiveXObject("Excel.Application");
var excel_file = excel.Workbooks.Open("Z:/SunCenter/Medicare Customer Experience/Hub/CaliforniaHUB/Plans/H0562_2013_082_EOC.xlsx");
var excel_sheet = excel.Worksheets("Sheet1");
gbid('span1').innerText = excel_sheet.Cells(1191,1).Value;
gbid('span2').innerText = excel_sheet.Cells(1192,1).Value;
gbid('span3').innerText = excel_sheet.Cells(1192,3).Value;
excel_file.Close()
excel.Quit()
Whenever the javascript runs (onload) it creates a process in the taskmanager/Processes. The problem is that it wont close it after use. When I run it again, it creates another one. Right now it's just pulling info from an excel file which is working just fine, but it just wont close the exe file in the taskmanager. I thought that excel_file.close would do it and I even put in another one, excel.quit, just in case. Sorry, I just wanted to make sure it worked. I've even taken one away now just in case of conflict but nada. Any help?
Comment: possible duplicate of [Windows 7 Gadget not releasing ActiveX object](http://stackoverflow.com/questions/7249465/windows-7-gadget-not-releasing-activex-object)


Here is another answer: According to Microsoft, because you're still holding a reference to excel when you call Quit(), Excel can't cleanly shut down. The recommendation is to call Quit(), set excel = null, then run CollectGarbage after a brief wait:
var idTmr = "";
function GetData() {
//...
excel.Quit();
excel = null;
idTmr = window.setInterval("Cleanup();",1);
function Cleanup() {
window.clearInterval(idTmr);
CollectGarbage();
Original sources:
http://support.microsoft.com/kb/266088
Windows 7 Gadget not releasing ActiveX object

Here is another answer: You need to call excel.Application.Quit(); instead of just excel.Quit();
Comment for this answer: It worked! Thank you! Someone needs to put 1 on the answer! It wont let me.
Comment for this answer: Why? [MSDN states](http://msdn.microsoft.com/en-us/library/office/ff839269(v=office.14).aspx) that `excel.Quit` should be sufficient to quit excel. I'm not saying you're wrong, I'd just like to know why this would make a difference.
Comment for this answer: @user1739280, if this answer solved your problem, you should [mark it as the accepted answer](http://meta.stackexchange.com/a/5235).

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:06/25/13', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<javascript><html><excel><activex>', 'Title': 'Closing Excel ActiveX object from JavaScript leaves excel.exe in memory', 'ViewCount': 8461, 'id': 17309231, 'user_AboutMe': None, 'user_AccountId': 1929578.0, 'user_DisplayName': 'user1739280', 'user_Reputation': 73.0, 'user_Views': 51.0, 'user_id': 1739280.0}}