473,396 Members | 2,087 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,396 software developers and data experts.

Excel instance won't close

I am running two visual basic modules in Access and keep coming across an annoying problem.
Both the vb modules transfer an excel spreadsheet to an access database but for some reason after the module has executed the excel spread sheets remain open in memory.
So if for some reason i try to go open the spreadsheets in excel i get a message saying that the spreadsheet is locked and can only be open in read-only mode.
When i press Ctrl+Alt+Delete, open task manager, and go to processes i can see two EXCEL.EXE process's running.
Once I end the process i can open the spread sheet and use it but otherwise it stays locked.

I researched online and came across the following code:

Expand|Select|Wrap|Line Numbers
  1. myExcelApp.ActiveWorkbook.Close
  2. myExcelApp.Application.Quit
I tried using this code and it solved half my problem. So now what its doing is closing one of the EXCEL.EXE processes but one still remains open.

What kind of code can I use to close/exit all spreadsheets that might be open in memory.
Dec 19 '07 #1
9 3127
Dököll
2,364 Expert 2GB
I am running two visual basic modules in Access and keep coming across an annoying problem.
Both the vb modules transfer an excel spreadsheet to an access database but for some reason after the module has executed the excel spread sheets remain open in memory.
So if for some reason i try to go open the spreadsheets in excel i get a message saying that the spreadsheet is locked and can only be open in read-only mode.
When i press Ctrl+Alt+Delete, open task manager, and go to processes i can see two EXCEL.EXE process's running.
Once I end the process i can open the spread sheet and use it but otherwise it stays locked.

I researched online and came across the following code:

Expand|Select|Wrap|Line Numbers
  1. myExcelApp.ActiveWorkbook.Close
  2. myExcelApp.Application.Quit
I tried using this code and it solved half my problem. So now what its doing is closing one of the EXCEL.EXE processes but one still remains open.

What kind of code can I use to close/exit all spreadsheets that might be open in memory.
Hello Hello!

It looks like you are missing:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Set YourWorkSheet = Nothing
  3. Set YourWorkBook = Nothing
  4. Set YourApp = Nothing
  5.  
  6.  
Something like that, I think you need to say that:-)

Try it!
Dec 20 '07 #2
Killer42
8,435 Expert 8TB
Yeah, you need to close/release/whatever all of the objects you create.
Dec 20 '07 #3
I tried that and it's closing only one of the EXCEL.EXE 's while one remains open.

Also, is this the correct command or am I doing this incorrectly?

Set myExcelAppWorksheets = Nothing
Set myExcelAppWorkBooks = Nothing
Set myExcelApp = Nothing

Instead of YourWorkSheet and YourWorkBook I would use myExcelApp.
Dec 20 '07 #4
Killer42
8,435 Expert 8TB
As far as I know it looks alright. However, as a general rule aren't you normally supposed to Close each object before setting your reference to Nothing?

(I don't work a lot with objects, so don't assume I know what I'm talking about.)
Dec 20 '07 #5
Dököll
2,364 Expert 2GB
Great point, I dunno objects:-)

...perhaps close is also needed. I would try them both; it looks like it is working. I'll check the code to see if anything's a miss there.

Does it give your the same treatment though? I am not sure if you said that...

In a bit!
Dec 21 '07 #6
Dököll
2,364 Expert 2GB
Great point, I dunno objects:-)

...perhaps close is also needed. I would try them both; it looks like it is working. I'll check the code to see if anything's a miss there.

Does it give your the same treatment though? I am not sure if you said that...

In a bit!
Please fogive me if I seem standoffish with the code, I have not worked too much with excel. Try nonetheless, and I will also give it a whirl and see if anything pops up. I must admin please I am not sure what the resluts will be when you run it. Let's give it a go and see:-)

Expand|Select|Wrap|Line Numbers
  1.  
  2. With myWorkBook
  3.  
  4.           .Save
  5.  
  6.           .Close
  7. End With
  8.  
  9. myApp.Quit
  10.    Set myWorkSheet = Nothing
  11.    Set myWorkBook = Nothing
  12.    Set myApp = Nothing
  13.  
Thing is I messed it up so much that I do not what going on with it.
I probably made a typo up there too:-)

Dököll
Dec 21 '07 #7
kadghar
1,295 Expert 1GB
try making the Excel.Application visible, then close it.

It's not the "right" way, but it works well.
Jan 9 '08 #8
TRUE FIX ... or rather ... THIS IS HOW IT SHOULD BE


dim appExcel as Excel.Application <- this is variable declaration only
.
. declare whatever you need
.

Set appExcel = NEW Excel.Application <--- this line declares appExcel as New Object to be run in a new instance rather than object to be run within MS ACCESS instance.
.
. set whatever you need (including worbook and worksheet)
.


Try eliminating SET statment of appExcel and run your program .. See task list
Try setting appExcel without NEW declaration and run your program ... See task list
Try setting appExcel with NEW declaration and run your program ... See task list

.
. do your stuff here
.

workbook.save
workbook.close

set worksheet=nothing
set workbook=nothing
appExcel.quit
set appExcel=nothing

It took me about 1 day to figure things out ( as I missed NEW declaration in the set statement... so I hope this would benefit someone somewhere ).

excel should close with above standard closing statements

if you run recursive function/procedure with NEW instance of appExcel ... you need to close each instance. I suggest you DECLARE and set appExcel OUTSIDE the RECURSIVE procedure/function so that you only have 1 instance of appExcel running and pass the object as a parameter (if possible-i havent tried it but i think it should work)...using standard VBA programming it will be hard to close each instance without an object identifier .

if you declare the appExcel outside any function or procedure (public declaration), you may have EXCEL lingering until you close MS ACCESS.

SilentV8
Feb 17 '08 #9
Killer42
8,435 Expert 8TB
TRUE FIX ...
Thanks for sharing. I'm sure it will be useful for others with similar problems.
Feb 17 '08 #10

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

Similar topics

14
by: IanW | last post by:
I don't know if this is in the right place but.. I am writing a VB.Net Class Library which uses Excel to produce workbooks If I create an instance of Excel and then close it I can get .NET to...
3
by: Otie | last post by:
I found the following under the GetObject help notes and in the example for GetObject: "This example uses the GetObject function to get a reference to a specific Microsoft Excel worksheet...
1
by: Rick Brown | last post by:
After reading 30+ threads on the subject and implementing pertinent changes I still have an instance of Excel that won't close. I hope its due to my poor coding and someone can spot the error....
6
by: Matthew Wieder | last post by:
I have the following requirements: Build a stand-alone C# application that asks the user to click in a cell in an Excel spreadsheet, and then displays the address of that cell in the C#...
6
by: Mark | last post by:
I was able to get procedure to work in a VB.Net Windows application, and want to get it to work within a ASP.Net page. It won't create the instance of Excel. It blows up on the CreateObject...
5
by: Wenke Ji | last post by:
Hi I open a Excel workbook using below API: Set ExcelServer = CreateObject("EXCEL.Application") Set TargetWorkbook = ExcelServer.Workbooks.Open (CurrentBook) Befor the programm exit , I use...
16
by: alexia.bee | last post by:
Hi all, In some weird reason, excel instance won;t die if i remove the comment from 4 lines of setting values into struct. here is a snipcode public...
9
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso...
10
by: Hendri Adriaens | last post by:
Hi, I'm trying to automate the creation of an excel file via COM. I copied my code below. I read many articles about how to release the COM objects that I create. The code below runs just fine...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.