ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel Won't Unload... (https://www.excelbanter.com/excel-programming/314073-excel-wont-unload.html)

Steven8R

Excel Won't Unload...
 

I have an app that has a couple grids. If I load either grid from a
Excel file, no matter what I've tried, Excel will close, but no
disappear from the task manager.

I was getting all kinds of strange errors; and sometimes my cod
worked, sometimes it didn't. I finally figured out that EXCEL.EXE wa
still running (in task manager), and if I tried to load another gri
from an Excel file I'd get errors. For example, I had severa
formatting commands that sometimes worked - but ONLY if I loaded tha
grid FIRST.

Anyways, I am opening Excel, and asking for a file name, doing stuff
then want to close via code in a sub when I'm done:

Set objExcel = CreateObject("Excel.Application")
Set objBook = objExcel.Workbooks.Add
Set objSheet = objExcel.Sheets(1)
< save as xxx

to close:

objExcel.DisplayAlerts = False

' objBook.Close(SaveChanges:=False) ' <-- ** or True **

ActiveWorkbook.Close False
ThisWorkbook.Close
objExcel.Close
objExcel.Quit

Set objExcel = Nothing
Set objSheet = Nothing
Set objBook = Nothing

Tyring all kinds of stuff - but EXCEL.EXE still in task manager! An
ideas? Thanks

--
Steven8
-----------------------------------------------------------------------
Steven8R's Profile: http://www.excelforum.com/member.php...fo&userid=1548
View this thread: http://www.excelforum.com/showthread.php?threadid=27064


K Dales[_2_]

Excel Won't Unload...
 
Looks to me like you are using the right steps - that is, closing the book,
quitting the app, setting all your Excel object references to Nothing. That
should be enough to clear out the session you started. Unless something else
is happening in the code you did not include. Do you create any other object
variables, and are they pointing to anything from that Excel session? Are
you sure the code you list at the end is actually running? Not bypassed, for
example, by an error handler?

If you still can't figure it out, to debug you might try this: if your
objExcel is not visible, set Visible to true, then try breaking your code at
critical points (set breakpoints, or do like I do - Msgbox that pops up with
message saying where I am in code, then I Ctrl-Break to get to the debugger
if I want to). I would suggest trying after each critical step - saving the
workbook, closing it, quitting the session, and setting everything to
Nothing. See what the state of the session is at those points by looking at
the app, using the debugger, peeking in Task Manager. Might help you find
where it is getting hung up.

Wish I could help some more, but looks like some debuggin is in order.
Good luck...

"Steven8R" wrote:


I have an app that has a couple grids. If I load either grid from an
Excel file, no matter what I've tried, Excel will close, but not
disappear from the task manager.

I was getting all kinds of strange errors; and sometimes my code
worked, sometimes it didn't. I finally figured out that EXCEL.EXE was
still running (in task manager), and if I tried to load another grid
from an Excel file I'd get errors. For example, I had several
formatting commands that sometimes worked - but ONLY if I loaded that
grid FIRST.

Anyways, I am opening Excel, and asking for a file name, doing stuff,
then want to close via code in a sub when I'm done:

Set objExcel = CreateObject("Excel.Application")
Set objBook = objExcel.Workbooks.Add
Set objSheet = objExcel.Sheets(1)
< save as xxx

to close:

objExcel.DisplayAlerts = False

' objBook.Close(SaveChanges:=False) ' <-- ** or True **

ActiveWorkbook.Close False
ThisWorkbook.Close
objExcel.Close
objExcel.Quit

Set objExcel = Nothing
Set objSheet = Nothing
Set objBook = Nothing

Tyring all kinds of stuff - but EXCEL.EXE still in task manager! Any
ideas? Thanks!


--
Steven8R
------------------------------------------------------------------------
Steven8R's Profile: http://www.excelforum.com/member.php...o&userid=15483
View this thread: http://www.excelforum.com/showthread...hreadid=270640



Dave Peterson[_3_]

Excel Won't Unload...
 
Untested, but maybe...

objexcel.ActiveWorkbook.Close False
objexcel.ThisWorkbook.Close false

(fully qualified)

Steven8R wrote:

I have an app that has a couple grids. If I load either grid from an
Excel file, no matter what I've tried, Excel will close, but not
disappear from the task manager.

I was getting all kinds of strange errors; and sometimes my code
worked, sometimes it didn't. I finally figured out that EXCEL.EXE was
still running (in task manager), and if I tried to load another grid
from an Excel file I'd get errors. For example, I had several
formatting commands that sometimes worked - but ONLY if I loaded that
grid FIRST.

Anyways, I am opening Excel, and asking for a file name, doing stuff,
then want to close via code in a sub when I'm done:

Set objExcel = CreateObject("Excel.Application")
Set objBook = objExcel.Workbooks.Add
Set objSheet = objExcel.Sheets(1)
< save as xxx

to close:

objExcel.DisplayAlerts = False

' objBook.Close(SaveChanges:=False) ' <-- ** or True **

ActiveWorkbook.Close False
ThisWorkbook.Close
objExcel.Close
objExcel.Quit

Set objExcel = Nothing
Set objSheet = Nothing
Set objBook = Nothing

Tyring all kinds of stuff - but EXCEL.EXE still in task manager! Any
ideas? Thanks!

--
Steven8R
------------------------------------------------------------------------
Steven8R's Profile: http://www.excelforum.com/member.php...o&userid=15483
View this thread: http://www.excelforum.com/showthread...hreadid=270640


--

Dave Peterson


RWN

Excel Won't Unload...
 
Steven;
This will be of no help but may I ask what version you are running?
I ask because I have encountered the same problem in Word'03.
I was going to try it in '97 and 2k when I saw your post.

My apologies for the interruption, but I'm getting a headache!
--
Regards;
Rob
------------------------------------------------------------------------
"Steven8R" wrote in message
...

I have an app that has a couple grids. If I load either grid from an
Excel file, no matter what I've tried, Excel will close, but not
disappear from the task manager.

I was getting all kinds of strange errors; and sometimes my code
worked, sometimes it didn't. I finally figured out that EXCEL.EXE was
still running (in task manager), and if I tried to load another grid
from an Excel file I'd get errors. For example, I had several
formatting commands that sometimes worked - but ONLY if I loaded that
grid FIRST.

Anyways, I am opening Excel, and asking for a file name, doing stuff,
then want to close via code in a sub when I'm done:

Set objExcel = CreateObject("Excel.Application")
Set objBook = objExcel.Workbooks.Add
Set objSheet = objExcel.Sheets(1)
< save as xxx

to close:

objExcel.DisplayAlerts = False

' objBook.Close(SaveChanges:=False) ' <-- ** or True **

ActiveWorkbook.Close False
ThisWorkbook.Close
objExcel.Close
objExcel.Quit

Set objExcel = Nothing
Set objSheet = Nothing
Set objBook = Nothing

Tyring all kinds of stuff - but EXCEL.EXE still in task manager! Any
ideas? Thanks!


--
Steven8R
----------------------------------------------------------------------

--
Steven8R's Profile:

http://www.excelforum.com/member.php...o&userid=15483
View this thread:

http://www.excelforum.com/showthread...hreadid=270640





All times are GMT +1. The time now is 11:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com