Access Bug??

L

Luis

Hello.
I have a module that creates 2 different Excel application
objects. I create one object, process the object and do
set Wbxl=Nothing. I repeat the same process to the second
object.
The big problem is that only one of the objects is killed.
If i go to Windows Task Manager there is still one
Excel.Exe process. This causes that when i close the
database I get an Excel exception error.
Is it an Access bug or am i doing something wrong? The
code i'm using looks like this:

Public Function Process_cell()
Dim wbxl As Object
Dim wbxl2 As Object

Set wbxl = CreateObject("Excel.application")
Path = "mypath"
wbxl.DisplayAlerts = False
wbxl.Workbooks.Open Path
DoCmd.TransferSpreadsheet acImport,
acSpreadsheetTypeExcel9, "mytable1", "Path",
True, "A2:IV65536"
wbxl.ActiveWorkbook.Close savechanges:=False
wbxl.Quit
Set wbxl = Nothing


Set wbxl2 = CreateObject("Excel.application")
Path = "mypath2"
wbxl2.DisplayAlerts = False
wbxl2.Workbooks.Open Path
DoCmd.TransferSpreadsheet acImport,
acSpreadsheetTypeExcel9, "mytable2", "Path",
True, "A2:IV65536"
wbxl2.ActiveWorkbook.Close savechanges:=False
wbxl2.Quit
Set wbxl2 = Nothing
End Function
 
K

Ken Snell [MVP]

You're using ActiveWorkbook, which creates a new reference to the open
workbook. As such, because you don't "set it to nothing", it keeps Excel
open.

Change this line:
wbxl.ActiveWorkbook.Close savechanges:=False

to this:
wbxl.Workbooks(1).Close savechanges:=False
 
L

Luis

Ken, I've tryied to change this but the process still
remains. It doesn't "kill" the process.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top