Hi Folks,

I have spent much of the afternoon searching the forum and thinking I had solved my issue with Excel processes not terminating when referenced from my VB6 application. I have not.

While I understand the concepts laid out in si_the_geek's thread on Excel here (http://vbforums.com/showthread.php?t=391665) as well as eer3's answers at http://vbforums.com/showthread.php?t=68080, I still get the problem when I bring a workbook into the mix.

Here is a project created from scratch, referencing Excel as outlined in si's post:

VB Code:
  1. Dim oXLApp As Excel.Application         'Declare the object variables
  2. Dim oXLBook As Excel.Workbook
  3. Dim oXLSheet As Excel.Worksheet
  4.  
  5.  
  6. Private Sub Command1_Click()
  7.   Set oXLApp = New Excel.Application    'Create a new instance of Excel
  8.   Set oXLBook = oXLApp.Workbooks.Add    'Add a new workbook
  9.   Set oXLSheet = oXLBook.Worksheets(1)  'Work with the first worksheet
  10. End Sub
  11.  
  12. Private Sub Command2_Click()
  13.   Set oXLSheet = Nothing             'disconnect from the Worksheet
  14.   oXLBook.Close SaveChanges:=False   'Close (and disconnect from) the Workbook
  15.   Set oXLBook = Nothing
  16.   oXLApp.Quit                        'Close (and disconnect from) Excel
  17.   Set oXLApp = Nothing
  18. End Sub

This is a literal cut and paste of the thread, yet after clicking Command2, Excel.exe remains in the task manager. After re-reading si's thread and the one eer3 posted to, I created another new project, this time without referencing Excel in VB6:

VB Code:
  1. Dim oXLApp As Object
  2. Dim oXLBook As Object
  3.  
  4. Private Sub Command1_Click()
  5.     Set oXLApp = CreateObject("Excel.Application")
  6.     oXLApp.Visible = True  
  7. End Sub
  8.  
  9. Private Sub Command2_Click()
  10.     oXLApp.Visible = False
  11.     oXLApp.quit
  12.     Set oXLApp = Nothing
  13. End Sub
  14.  
  15. Private Sub Command3_Click()
  16.     Set oXLBook = oXLApp.workbooks.Add
  17. End Sub
  18.  
  19. Private Sub Command4_Click()
  20.     oXLBook.Close
  21.     Set oXLBook = Nothing
  22. End Sub

In this case, I broke out the creation of the application and the addition of the workbook. Running command 1 and 2 had the desired results. Excel disappeared from the task manager. However, as soon as command 3 and 4 were brought in to the mix (i.e. 1_Create Excel 3_add a workbook 4_ close the workbook 2_close Excel), the problem re-occurred. Obviously the problem is when I bring the work book into the equation (which is confirmed by commenting out workbook and worksheet references n the first code example).

So what am I doing wrong here? These are cut and pastes out of threads where others are claiming their problems were solved. Are these solutions out dated? I run XP home SP2 with VB6 and Office XP (Excel 10). Thanks for any help