Solved

Cleanning up after Excel Object

Posted on 2012-03-27
4
445 Views
Last Modified: 2012-06-21
hi Experts

I have the below code in Access, and running it once works, but not repeatedly.  I hav also noticed that under Task Manager, when running this code my number of proccess go up by 4, but go down only by 3, leaving EXCEL.EXE *32 listed.

I'm setting my 2 excel objects to nothing, why it isn't cleanning up?

    Dim strFilePath As String
    Dim intRowCount, intRow As Integer
    Dim intColCount, intCol As Integer
    Dim objXL As Excel.Application
    Dim objSheet As Excel.Worksheet
    
    Dim fso
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    strFilePath = Environ("userProfile") & "\Desktop\SalesByProduct.xls"
    If fso.FileExists(strFilePath) Then Kill strFilePath
    
    Set fso = Nothing
    
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "qryProdTotals", strFilePath, True
    
    Set objXL = CreateObject("Excel.Application")
    objXL.Workbooks.Open strFilePath
    Set objSheet = objXL.ActiveWorkbook.Worksheets("qryProdTotals")
    
    intRowCount = objSheet.UsedRange.Rows.Count
    intColCount = objSheet.UsedRange.Columns.Count
    
    objSheet.Cells(intRowCount + 2, 1).Select
    With objXL.ActiveCell
        .Value = "T O T A L S :"
        .Font.Bold = True
        .Interior.ColorIndex = 16
    End With
    
    For intCol = 2 To intColCount
    
        objSheet.Cells(intRowCount + 2, intCol).Select
        With objXL.ActiveCell
            .Value = objXL.WorksheetFunction.Sum(Range(Cells(2, intCol), Cells(intRowCount, intCol)))
            .Font.Bold = True
            .Interior.ColorIndex = 16
        End With
    
    Next
    
    'Hilight Row1
    
    
    'Format col2...colMax, Row...rowMax+2
    
    objXL.ActiveWorkbook.Save
    objXL.Quit
    
    Set objSheet = Nothing
    Set objXL = Nothing
    MsgBox "Report Exported to " & strFilePath
    

'***Export to Excel END***

Open in new window

0
Comment
Question by:APD_Toronto
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 40

Accepted Solution

by:
als315 earned 500 total points
ID: 37775206
I've tested it in Windows 7 32 bit, Access 2010 and all is working without problems. Excel is  unloaded. Only one comment: you have late binding of Excel an it will be better to declare your variables as:
    Dim objXL As Object
    Dim objSheet As Object
In thhis case you will need no reference to Excel library.
0
 

Author Comment

by:APD_Toronto
ID: 37777001
If i do, i get at Line 36 re Cells:
Sub or function not defined.
0
 

Author Comment

by:APD_Toronto
ID: 37777008
Why can't i clean up Excel *32
0
 

Author Comment

by:APD_Toronto
ID: 37777249
I keep errorring on Li 36.  Now with my code, before Li 56 I added:
 Shell "TaskKill /F /T /IM Excel.exe", vbHide

First execution works great, second at Li36 I get
The remote server machine does not exist or is unavailable
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question