473,396 Members | 1,997 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 object still in memory after Access app runs

RE: Access 2003/Excel 2003
Problem:
After I close the Access application completely, I go out to the Task
Manager and there is an Excel.exe object still sitting out there.

My Access application creates an Excel file (MyTestFile.XLS) just fine
per the code submitted here. This code closes the Excel file created
and close the Excel application, leaving the Access app open. Then I
close Access. After Access is closed, I go to the task mgr and an
Excel object is still out there.

Question:
How (using VBA) can I check the Task Manager of the Workstation, check
to see if an Excel object is there, and if it is there, flush it from
the Task Manager?
When this output file is created, it needs to be saved regardless.
Can this be done?
This code is from the subroutine that loops through a recordset to
create the Excel file.
<begin code>
'Dim the Excel objects smallest to largest...
Dim objXL As Excel.Application
Dim objWkb As Excel.Workbook
Dim objSht As Excel.Worksheet

Set objXL = New Excel.Application

With objXL
Set objWkb = .Workbooks.Open(conWKB_NAME)
On Error Resume Next
Set objSht = objWkb.Worksheets(conSHT_NAME)
If Not Err.Number = 0 Then
'MsgBox conSHT_NAME & " was not found in ExcelFile: " &
conWKB_NAME & vbCrLf & _
"so data will be pasted in a new sheet labeled: " &
conSHT_NAME
Set objSht = objWkb.Worksheets.Add
objSht.Name = conSHT_NAME
End If
Err.Clear
On Error GoTo 0
> ....Do Excel stuff here
to create the output .XLS file.... <<

'Close Excel objects in reverse order they were declared...
'Closing Sheet, Workbook, Application...
Set objSht = Nothing
Set objWkb = Nothing
Set objXL = Nothing
<end code>

thnx....

Mar 21 '07 #1
3 7136
On Mar 21, 3:48 pm, rlntemp-...@yahoo.com wrote:
RE: Access 2003/Excel 2003
Problem:
After I close the Access application completely, I go out to the Task
Manager and there is an Excel.exe object still sitting out there.

My Access application creates an Excel file (MyTestFile.XLS) just fine
per the code submitted here. This code closes the Excel file created
and close the Excel application, leaving the Access app open. Then I
close Access. After Access is closed, I go to the task mgr and an
Excel object is still out there.

Question:
How (using VBA) can I check the Task Manager of the Workstation, check
to see if an Excel object is there, and if it is there, flush it from
the Task Manager?
When this output file is created, it needs to be saved regardless.
Can this be done?

This code is from the subroutine that loops through a recordset to
create the Excel file.
<begin code>
'Dim the Excel objects smallest to largest...
Dim objXL As Excel.Application
Dim objWkb As Excel.Workbook
Dim objSht As Excel.Worksheet

Set objXL = New Excel.Application

With objXL
Set objWkb = .Workbooks.Open(conWKB_NAME)
On Error Resume Next
Set objSht = objWkb.Worksheets(conSHT_NAME)
If Not Err.Number = 0 Then
'MsgBox conSHT_NAME & " was not found in ExcelFile: " &
conWKB_NAME & vbCrLf & _
"so data will be pasted in a new sheet labeled: " &
conSHT_NAME
Set objSht = objWkb.Worksheets.Add
objSht.Name = conSHT_NAME
End If
Err.Clear
On Error GoTo 0
> ....Do Excel stuff here
to create the output .XLS file.... <<

'Close Excel objects in reverse order they were declared...
'Closing Sheet, Workbook, Application...
Set objSht = Nothing
Set objWkb = Nothing
Set objXL = Nothing
<end code>

thnx....

throw the following at the end (Where you close the sheet):

objWkb.close
objXL.quit

Mar 21 '07 #2
rlntemp,

You never close the workbook: objWkb.Close

You only destroyed the reference to it.

-- Bill

<rl*********@yahoo.comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
RE: Access 2003/Excel 2003
Problem:
After I close the Access application completely, I go out to the Task
Manager and there is an Excel.exe object still sitting out there.

My Access application creates an Excel file (MyTestFile.XLS) just fine
per the code submitted here. This code closes the Excel file created
and close the Excel application, leaving the Access app open. Then I
close Access. After Access is closed, I go to the task mgr and an
Excel object is still out there.

Question:
How (using VBA) can I check the Task Manager of the Workstation, check
to see if an Excel object is there, and if it is there, flush it from
the Task Manager?
When this output file is created, it needs to be saved regardless.
Can this be done?
This code is from the subroutine that loops through a recordset to
create the Excel file.
<begin code>
'Dim the Excel objects smallest to largest...
Dim objXL As Excel.Application
Dim objWkb As Excel.Workbook
Dim objSht As Excel.Worksheet

Set objXL = New Excel.Application

With objXL
Set objWkb = .Workbooks.Open(conWKB_NAME)
On Error Resume Next
Set objSht = objWkb.Worksheets(conSHT_NAME)
If Not Err.Number = 0 Then
'MsgBox conSHT_NAME & " was not found in ExcelFile: " &
conWKB_NAME & vbCrLf & _
"so data will be pasted in a new sheet labeled: " &
conSHT_NAME
Set objSht = objWkb.Worksheets.Add
objSht.Name = conSHT_NAME
End If
Err.Clear
On Error GoTo 0
> ....Do Excel stuff here
to create the output .XLS file.... <<

'Close Excel objects in reverse order they were declared...
'Closing Sheet, Workbook, Application...
Set objSht = Nothing
Set objWkb = Nothing
Set objXL = Nothing
<end code>

thnx....

Mar 21 '07 #3
>>objWkb.close
objXL.quit<<

Matt,
This worked! Thank you for this suggestion.
When my application closes, the Excel reference in Task Manager is
destroyed as it should be.

I inherited all this code, so am stumped on a couple more items
here....

When ICCDataOut.XLS exists:
A new sheet is added to this .XLS file (sheet2, sheet3, sheet4, etc.)
This is ok, but I might look later into creating a custom string for a
particular run and placing the date-time on the sheet tab name.

I probably need to interrogate to see if ICCDataOut.XLS exists first.
(Are there efficient ways to do this in VBA?)
If it exists, check to see if the there is a sheet called
"ICCDataSheet". If there is not, then use "ICCDataSheet" as the sheet
name.
If the output file does not exist, I need to open the Excel object
with a new file, run code to load it up, then save the sheet and file
upon closing the Access form.

Currently, when the output .XLS file does not exist, this line errors:
Set objWkb = .Workbooks.Open(conWKB_NAME)
The error is "1004-Application defined or object defined error"
Is there a way to bypass this error so it would open a new sheet
anyway in the event that this file did not exist prior to creation?
Here is the code I have thus far:
Const conSHT_NAME = "ICCDataSheet"
Const conWKB_NAME = "C:\ICC\ICCDataOut.XLS"

Set objXL = New Excel.Application

With objXL
Set objWkb = .Workbooks.Open(conWKB_NAME)
On Error Resume Next
Set objSht = objWkb.Worksheets(conSHT_NAME)
If Not Err.Number = 0 Then
' conSHT_NAME was not found in Excel File - conWKB_NAME
' data will be pasted in a new sheet labeled: " &
conSHT_NAME
Set objSht = objWkb.Worksheets.Add
objSht.Name = conSHT_NAME
DebugPrint "Excel File is: " & conWKB_NAME & "/ Added
New sheet: " & objSht.Name
Else
DebugPrint "Excel File is: " & conWKB_NAME & "/ Using
Existing sheet: " & objSht.Name
End If

Err.Clear
On Error GoTo 0 'not sure if this is actually needed here (?)

End With
thnx....

Mar 22 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: geronimo_me | last post by:
Hi, I am trying to run an Excel macro from an Access module, however when I run the code the macro runs but then I get an error in Access. The error is: Run-time error "440", Automation error. ...
1
by: Jake | last post by:
Good Day All, Sorry if I am posting in the wrong forum, hopefully someone will be able to push me in the right direction. What I am trying to accomplish is allowing a client to upload an Excel...
3
by: hari krishna | last post by:
hi, I am generating excel reports through vb.Net. After creating excel.application and the report is generated, each report leaves Excel in memory. I can see them in task manager in Process tab...
8
by: jack | last post by:
Access is denied. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it...
12
by: D. Shane Fowlkes | last post by:
This most likely belongs in another forum but I thought I'd start here. I have a COM Object written in VB6. The DLL will access MS Excel and use it's Object Library to write a customized report...
4
by: Rich Wallace | last post by:
Hi all, I have a VB app that runs and manages individual XLS files within a single COM object. Upon processing the final fie, I attempt to close out the EXCEL object and release it using...
5
by: RJN | last post by:
Hi I'm invoking the excel object from ASP.Net application. My development machine is Windows 2000 and MS Office is installed on my m/c. I have added reference to the Excel COM object, I have...
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...
16
by: Phil Stanton | last post by:
I have a form with a button which is supposed to open an Excel file (With lots of Macros /VBA) in it. The Excel file gets it's data from the Access program Here is the code Private Sub...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.