By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,243 Members | 1,079 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,243 IT Pros & Developers. It's quick & easy.

Closing Excel properly

P: 2
Hello, I'm fairly new to javascript. I'm making a website for my personal use that will read from Excel and display some data on an HTML page and I've been learning javascript as I go.

A problem I have is when I leave the website running overnight (it refreshes itself every minute), an error eventually pops up that says
"Not enough memory to run Microsoft Office Excel. Please close other applications and try again."
Internet Explorer also gives the error "Automation Server can't create object" on the line
Expand|Select|Wrap|Line Numbers
  1. var excel = new ActiveXObject("Excel.Application");
so anyways heres my code for opening excel
Expand|Select|Wrap|Line Numbers
  1. var excel = new ActiveXObject("Excel.Application");
  2. excel.visible=false;
  3. var excelfile = excel.Workbooks.Open("displayinfo.xls");
  4. var excelsheet = excel.Worksheets("Sheet1");
I use actually vbscript to go through task manager and kill the "EXCEL.EXE" process, but that didnt help get excel out of memory and I tried this code to no avail-
Expand|Select|Wrap|Line Numbers
  1. excelfile.Close(false);
  2. excel.Quit();
  3. excel = null;
  4. setTimeout("CollectGarbage()",1);
I've been searching the internet for a solution for days now, and I've tried my best to solve this on my own. Any help on how to correctly release excel from memory would be greatly appreciated.
Aug 8 '07 #1
Share this Question
Share on Google+
4 Replies

Expert Mod 15k+
P: 16,027
Welcome to TSDN!

This is not really a Javascript question, but since it's JScript...

Anyway, you need to call the Quit() method on the Application object:
Expand|Select|Wrap|Line Numbers
  1. excel.Application.Quit();
See example link.
Aug 8 '07 #2

P: 2
heyy, sorry for bumping such an old thread, but I finally got my website to stop running out of memory overnight.

Expand|Select|Wrap|Line Numbers
  1. excelfile.Close(false);
  2. excel.Quit();
  3. excel.Application.Quit();
  4. excel = null;
  5. excelfile = null;
  6. excelsheet = null;
  7. CollectGarbage();
  8. setTimeout("CollectGarbage()",1);
I'm not sure if the excelfile.Close(false) is necessary, I'm also not sure which one was needed Quit or Application.Quit, but this website of mine has to be literally finished tomorrow, so I'm leaving it in there for now, I really cut it close to the wire trying to solve this problem lol. I learned from a google search that Excel has a bug and doesn't shut down after calling the Quit() method when automating from JScript. To work around this problem, the CollectGarbage() method is used to force JScript's garbage collection to occur almost immediately.

I just hate when I read threads started by people with similar problems as me, then they post a final "solved the problem kbye" but forget to mention how they solved it, so I just wanted to give a reply for anyone who happens to stumble across this thread with the same problem I had.
Aug 14 '07 #3

Expert Mod 15k+
P: 16,027
I think Application.Quit() is the correct method.
Aug 15 '07 #4

P: 1
Thanks a lot! :) ... yeah, this works... u are right... i did not need excel.Quit and excelfile.close but needed all the rest to successfully close excel!

Mar 25 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.