Closing an Excel Process through Access

Chiligoldva

New Member
Joined
Feb 6, 2004
Messages
7
Code:
 :banghead: I simply am at my wits end on this one. I am using XP and I have opened an Excel spreadsheet through Access to update. 

Dim objxl as object
dim objxl_book as object
dim objxl_sheet as object

set objxl = create object ("Excel.application")
objxl.visible = true
set objxl_book = objxl.workbooks.open("path\foldername\sheetname.xls")
set objxl_sheet = objxl_book.worksheets("Nameofsheet")

blah blah blah to transfer the data from the tables in Access to Excel sheet.
blah blah blah........etc.

at the end
objxl_book.save
 dim bkrupwrkbook
dim fso = createobject("scripting.fileSystemObject")
bkupwrkbook = "path\folder\nameoffile"
fso.copyfile "path\folder\sheetname, bkupwrkbook, true

set objxl_sheet = nothing
set objxl_book = nothing
objxl.quit
set objxl = nothing

when I open the task list to see if Excel has been released from the process tab
, it's still there!!! What the heck am I doing wrong? Can anyone help me? :pray: Thank you kind people.....I really need some insite. Chiligoldva
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
You're not alone with this; this has been a very common problem with Access/Excel automation and I don't believe that it's because of anything that you've done wrong. I'll try to see if I can dig up some links on how to deal with this.
 
Upvote 0
I had a similar problem just a couple weeks ago.
I settled on this which handled it, but only if all I did was paste things into cells...and if I didn't use any With...End With to handle objXl/objWKb

Code:
objXL.DisplayAlerts = False
objWkb.Close True, strFile
objXL.DisplayAlerts = True
objXL.Quit

One thing I was thinking of doing was tossing in a DOS command at the end to kill the PID but that's kinda ugly.

Mike
 
Upvote 0
I had this problem several months ago and don't remember where I found the answer, but setting usercontrol to true should let you close the instance of excel that was created. Here is your code with the added line:

set objxl_sheet = nothing
set objxl_book = nothing
objxl.usercontrol=true
objxl.quit
set objxl = nothing

When an Application object is created by using automation, the Visible and UserControl properties of the object are both set to False. Even though you think you are closing excel, it actually doesn't close (as you know) because you the user don't have permission to close it. The window containing excel will close, but the actual application doesn't unless the user has control of the application.
 
Upvote 0
For one common problem see
Program won't quit
http://www.tushar-mehta.com/excel/vba/xl_doesnt_quit/

Chiligoldva said:
Code:
 :banghead: I simply am at my wits end on this one. I am using XP and I have opened an Excel spreadsheet through Access to update. 

Dim objxl as object
dim objxl_book as object
dim objxl_sheet as object

set objxl = create object ("Excel.application")
objxl.visible = true
set objxl_book = objxl.workbooks.open("path\foldername\sheetname.xls")
set objxl_sheet = objxl_book.worksheets("Nameofsheet")

blah blah blah to transfer the data from the tables in Access to Excel sheet.
blah blah blah........etc.

at the end
objxl_book.save
 dim bkrupwrkbook
dim fso = createobject("scripting.fileSystemObject")
bkupwrkbook = "path\folder\nameoffile"
fso.copyfile "path\folder\sheetname, bkupwrkbook, true

set objxl_sheet = nothing
set objxl_book = nothing
objxl.quit
set objxl = nothing

when I open the task list to see if Excel has been released from the process tab
, it's still there!!! What the heck am I doing wrong? Can anyone help me? :pray: Thank you kind people.....I really need some insite. Chiligoldva
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top