Releasing Reference to an Excel Object 
Author Message
 Releasing Reference to an Excel Object

I have the following code to open an Excel SpreadSheet, populate it with
data, save it, and then close down Excel.

However, my app does not release the Excel Object (can be seen from the
Windows Task Manager as a running Process - EXCEL.EXE) until the application
has been closed.

Is there a way to make the vb app release the reference to the Excel object
and 'really' make it close Excel without terminating my vb application.

Thanks in advance for your help,    Kevin

Dim ExcelApp as Excel.Application
Dim ExcelWkb as Excel.WorkBook
Dim ExcelSht as Excel.WorkSheet

Set ExcelApp = New Excel.Application
Set ExcelApp = CreateObject("Excel.Application")
strExcelPath = App.Path & "\xyz.xlt"
Set ExcelWkb = ExcelApp.Workbooks.Open(strExcelPath)

'Do a bunch of number crunching

Call SaveSpreadSheet

ExcelWkb.Close
ExcelApp.Quit

Set ExcelSht = Nothing
Set ExcelApp = Nothing
Set ExcelWkb = Nothing



Tue, 17 Jun 2003 17:10:09 GMT  
 Releasing Reference to an Excel Object
Your code seems to work OK here (VB6 SP3 on Win2K)...but I'm not calling
SaveSpreadSheet, so I can't tell if that's the problem.

Are you making any other references to any excel objects that might not be
getting released?


Quote:
> I have the following code to open an Excel SpreadSheet, populate it with
> data, save it, and then close down Excel.

> However, my app does not release the Excel Object (can be seen from the
> Windows Task Manager as a running Process - EXCEL.EXE) until the
application
> has been closed.

> Is there a way to make the vb app release the reference to the Excel
object
> and 'really' make it close Excel without terminating my vb application.

> Thanks in advance for your help,    Kevin

> Dim ExcelApp as Excel.Application
> Dim ExcelWkb as Excel.WorkBook
> Dim ExcelSht as Excel.WorkSheet

> Set ExcelApp = New Excel.Application
> Set ExcelApp = CreateObject("Excel.Application")
> strExcelPath = App.Path & "\xyz.xlt"
> Set ExcelWkb = ExcelApp.Workbooks.Open(strExcelPath)

> 'Do a bunch of number crunching

> Call SaveSpreadSheet

> ExcelWkb.Close
> ExcelApp.Quit

> Set ExcelSht = Nothing
> Set ExcelApp = Nothing
> Set ExcelWkb = Nothing



Wed, 18 Jun 2003 02:37:59 GMT  
 Releasing Reference to an Excel Object
don't have a real good answer for why the Close and Quit don't do the
trick but you may want to consider the order in which you set your
object variables to Nothing.

Quote:
> Set ExcelSht = Nothing
> Set ExcelApp = Nothing
> Set ExcelWkb = Nothing

if the workbook reference is still active then the app object cannot be
set to nothing, so although your code does not error, it also does not
work. Generally... set to nothing in the reverse order that you do the
original sets in.

Set ExcelSht = Nothing
Set ExcelWkb = Nothing
Set ExcelApp = Nothing

Steve



Quote:
> I have the following code to open an Excel SpreadSheet, populate it
with
> data, save it, and then close down Excel.

> However, my app does not release the Excel Object (can be seen from
the
> Windows Task Manager as a running Process - EXCEL.EXE) until the
application
> has been closed.

> Is there a way to make the vb app release the reference to the Excel
object
> and 'really' make it close Excel without terminating my vb
application.

> Thanks in advance for your help,    Kevin

> Dim ExcelApp as Excel.Application
> Dim ExcelWkb as Excel.WorkBook
> Dim ExcelSht as Excel.WorkSheet

> Set ExcelApp = New Excel.Application
> Set ExcelApp = CreateObject("Excel.Application")
> strExcelPath = App.Path & "\xyz.xlt"
> Set ExcelWkb = ExcelApp.Workbooks.Open(strExcelPath)

> 'Do a bunch of number crunching

> Call SaveSpreadSheet

> ExcelWkb.Close
> ExcelApp.Quit

> Set ExcelSht = Nothing
> Set ExcelApp = Nothing
> Set ExcelWkb = Nothing

Sent via Deja.com
http://www.deja.com/


Wed, 18 Jun 2003 03:40:38 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Access to Excel Automation - Release Excel Object

2. Releasing object references....

3. VB won't release reference to COM object in use by another proces s

4. DirectX Events not releasing object reference

5. Killing client does not release object reference

6. Excel Object not releasing

7. Advanced : Excel doesn't close when i release it's object

8. Releasing Excel Objects from Memory

9. Passing an object reference by reference where the object has a default property

10. RELEASE OBJECTS --> RELEASE MEMORY

11. RELEASE OBJECTS --> RELEASE MEMORY

12. Excel Reference Object Library in VBA

 

 
Powered by phpBB® Forum Software