473,385 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Closing Excel properly

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
4 9844
acoder
16,027 Expert Mod 8TB
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
Yoduh
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
acoder
16,027 Expert Mod 8TB
I think Application.Quit() is the correct method.
Aug 15 '07 #4
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!

@Yoduh
Mar 25 '12 #5

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

Similar topics

2
by: lasmit42 | last post by:
Guys I am writing a program which reads the first cell of many Excel spreadsheets and then takes some actions. The problem that I am experiencing is that each Excel instance I create persists...
2
by: Mark | last post by:
Hi all, as many had, i have some problems terminating the excel-process. I implemented the solutions i found in this forums. Tried most combinations of them ;-). It still doesn't work. I'll...
2
by: Atley | last post by:
I have written an application that exports data from SQL to Excel. It all works perfectly except that if you open the Task Manager after running my application, there is an instance of Excel in...
2
by: ridawg | last post by:
Hey, I have some code where I open up Excel then loop through several cases to update several workbooks. Basically something like this (not showing all the code just basic structure). Try...
0
by: Jono | last post by:
Hello, I've been getting this message when closing excel (not necessarily when closing the workbook by itself, but when closing Excel and the workbook at the same time): ...
6
by: pleaseexplaintome_2 | last post by:
Help please. The excel instance is removed from task manager when I run the code below. If I uncomment the lines pertaining to a workbook, the instance of excel is not removed from task manager. ...
0
by: etp | last post by:
I am using office automation to open and read an excel doc on a K2 workflow server. I get an intermittent bug where I get a pop-up error box in excel saying "Not enough system resources to display...
1
by: fakehitswizard | last post by:
this is the correct way to close excel with C#. I've seen alot of other bogus posts ALL over the web that don't work, how frustrating. string savepath; bool foundPID; int ourPID = 0; int...
2
by: Ronin85 | last post by:
Hi , I recently have much pain working with excel application especially closing excel . I try several method but with no success i try to urge garbage collector to dispose excel application object,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.