DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Automation doesn't release Excel from memory ...

  1. #1
    Join Date
    Apr 2005
    Posts
    1

    Automation doesn't release Excel from memory ...

    Hello, I am new to the forum.

    I have a VB6 application that export data to Excel. When I was using Excel 2000, the application was working alright. We have moved to Excel 2003. Then my VB application suddenly not working well. It exports data to Excel alright, saves the file as before. But it does close and exit Excel as expected! Exiting the VB application does not help to close Excel either.

    Any idea how to resolve this? Thanks,

    Joe

  2. #2
    Join Date
    Mar 2005
    Posts
    110
    Hi Joe,

    I donot know if I got the same problem as your. Everytime, When I run my Vb application which call Excel application, I can see a Excel process by Windows Task Manager.
    I take the following code:
    Function IsExcelRunning() As Boolean
    Dim myApp As Object
    On Error Resume Next
    Set myApp = GetObject(, "Excel.Application")
    IsExcelRunning = (Err.Number = 0)
    Set myApp = Nothing
    Err.Clear
    End Function

    Private Sub Excel_Imports()
    ExcelRunning = IsExcelRunning()
    boolOpen = True
    If ExcelRunning Then
    Set myApp = GetObject(, "Excel.Application")
    Else
    Set myApp = CreateObject("Excel.Application")
    End If

  3. #3
    Join Date
    Dec 2003
    Posts
    2,750
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  4. #4
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    Can you explain "But it does close and exit Excel as expected! Exiting the VB application does not help to close Excel either." Do you mean "does NOT close"?
    How do you create your excel object? Are you closing your documents after having finish with them? Do you release the excel objects by hand or do you just leave VB to do it?

    To Paul: that article is for .NET. In .NET, it is much safer always to terminate COM objects using System.Runtime.InteropServices.Marshal.ReleaseComObject. This is from the MSDN page of ReleaseComObject:

    Note To ensure that the runtime callable wrapper and the original COM object are released, construct a loop from which you call this method until the returned reference count reaches zero.

    Marco

  5. #5
    Join Date
    Dec 2003
    Posts
    2,750
    Marco: Whoops! Forgot which forum I was in. Sorry about that.
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  6. #6
    Join Date
    Dec 2003
    Posts
    2,750
    You need to call the Quit method of the Excel Application object. If you don't, this can leave Excel in memory. You should also make certain to set an object variable to every Excel object you create so each can later be set to Nothing before terminating Excel. Implicitly created objects can also cause Excel to remain in memory.
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  7. #7
    Join Date
    Mar 2005
    Posts
    110
    Use above code, it can solve that problem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center