Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

End a process in task manager

Status
Not open for further replies.

scottian

Programmer
Jul 3, 2003
955
GB
ive finally managed to sort out a way of appending data to an excel spreadsheet, but wierdly this leaves Excel still running a process in the task manager. Does anyone know how to stop the process from a module in access?

"Children are smarter than any of us. Know how I know that? I don't know one child with a full time job and children."...Bill Hicks
 
Most likely Excel is open because you have not closed it..

Be sure to close the objects you opened and set the Excel Application object variable you are using equal to Nothing.


ExcelObject = Nothing

 
You want to close the application before set the variable to nothing

xlApp.quit
set xlApp=Nothing
 
scottian

You might also have an implicit reference to an excel object somewhere in your code
Code:
Dim objExcel As Excel.Application
Dim objWrkBook As Object
Dim objWrkSheet As Object

....
Set objExcel = CreateObject(Excel.Application)
objExcel.Workbooks.Add
'Here you create a new instance of ecxcel that stays live
'even if you close the objExcel and set it to Nothing
Set objWrkBook = [b]Excel.Workbooks(1)[/b] 
Set objWrkSheet = objWrkBook.WorkSheets(1)

...
Set objWrkSheet = Nothing
Set objWrkBook = Nothing
objExcel.Quit
Set objExcel= Nothing
 
It still leaves excel open,
Im not sure if i have an "implicit reference"

Dim db As Database
Dim XL_APP As Excel.Application
Dim XL_SHEET As Excel.Worksheet
Dim XL_WBOOK As Excel.Workbook
Set db = CurrentDb()
Set XL_APP = CreateObject("Excel.Application")
Set XL_WBOOK = XL_APP.Workbooks.Open("R:\MDP_DB" & "\Book1.xls")

--do something in excel--

Set XL_SHEET = Nothing
Set XL_WBOOK = Nothing
XL_APP.Quit
Set XL_APP = Nothing
DoCmd.SetWarnings True

"Children are smarter than any of us. Know how I know that? I don't know one child with a full time job and children."...Bill Hicks
 
Try:

Code:
XL_WBOOK.Close
Set XL_SHEET = Nothing
Set XL_WBOOK = Nothing
XL_APP.Quit
Set XL_APP = Nothing

Ed Metcalfe.

Please do not feed the trolls.....
 
thanks ed2020 but it still leaves it running

"Children are smarter than any of us. Know how I know that? I don't know one child with a full time job and children."...Bill Hicks
 
Please, post the code doing something in excel ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Ive sussed it. Played about with the the 'available actions' window (at least i think thats what its called)that pops up

XL_APP.Parent.Quit

XL_WBOOK.Close
Set XL_SHEET = Nothing
Set XL_WBOOK = Nothing
XL_APP.Quit
Set XL_APP = Nothing
XL_APP.Parent.Quit

But thanks for everyones attention to this post, it is appreciated.

"Children are smarter than any of us. Know how I know that? I don't know one child with a full time job and children."...Bill Hicks
 
Set XL_APP = Nothing
XL_APP.Parent.Quit

this make no sense ...
 
PHV,

In what way does it not make sense?
I dont understand what you mean.

The function im busy with converses with an excell spreadsheet. Actions are carried out by an access database which then finishes with it but the excel process is left running in the task manager. this means that when i want to rerun the function on a different spreadsheet i get an error. I have to open the task manager and manually end the process before i re-run the code. But my plan is to leave the function running with a whole bunch of files to work with.
Using 'XL_APP.Parent.Quit' ends the process. ive sat with task manger open while i run the code and i see the process close when the function ends.

So why does it not make sense?



"Children are smarter than any of us. Know how I know that? I don't know one child with a full time job and children."...Bill Hicks
 
Set XL_APP = Nothing

The above empties the object so performing any action with that object AFTER that without assigning a new object to it should not work.

XL_APP.Parent.Quit when immediately following the other line should give you an error.
 
I dont an error.

If i comment out 'XL_APP.Parent.Quit' then the code leaves the excel app running in task manager, if i then activate the XL_APP.Parent.Quit and run the code the process closes as it should. I will point out though that it only for the process that is started by the function, it doesnt kill any other excel process that is running, just the one that was started by the function. And i do need to reiterate that this was pure luck, i didnt work it out i just stumbled across it.

"Children are smarter than any of us. Know how I know that? I don't know one child with a full time job and children."...Bill Hicks
 
What happens if you switch the 2 lines of code?

I suspect it will do the same thing. This is at least the correct order of doing it even if the compiler is not behaving. It is better to do it correctly now than to have to fix it later when it mysteriously starts working.
 
it does the same thing, in that it switches off the process.

Can someone tell me what the problem is. I get the message that this should not work, but what is the reason why.

"Children are smarter than any of us. Know how I know that? I don't know one child with a full time job and children."...Bill Hicks
 
The XL_APP variable is a pointer to an instance of the Excel application. After executing the line "Set XL_APP = Nothing" the variable is no longer pointing at anything. Therefore attempting to access any of the object's methods or properties after running "Set XL_APP = Nothing" should result in a runtime error.

I've tested it on my PC and it does generate a runtime error. If you're not getting one something's not working quite.

Ed Metcalfe.

Please do not feed the trolls.....
 
Scottian- Earlier you noted " I will point out though that it only for the process that is started by the function, it doesnt kill any other excel process that is running, just the one that was started by the function." This sounds to me like you have more than one instance of Excel running. You only need one, you can open multiple workbooks with the one instance.
 
So how come the function kicks off another excel process.

My head hurts

"Children are smarter than any of us. Know how I know that? I don't know one child with a full time job and children."...Bill Hicks
 
scottian

The answer should be in your
Code:
--do something in excel--
which PHV asked you to post which was my first guess.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top