Hello,

I've got a problem with Excel which is really winding me up.
I've worked through quite a few similar problem reports in the forums but to no avail ...

The problem is that the following piece of code will leave an excel process running until the application is closed (i.e. sub main terminates, trace through the code to verify):

Sub main()

Dim xl As Excel.Application
Dim wb As Excel.Workbook

Set xl = CreateObject("Excel.Application")
xl.DisplayAlerts = False

Set wb = xl.Workbooks.Open("c:\test.xls")

'The following line causes the problem
Selection.Clear

Set wb = Nothing

xl.Quit
Set xl = Nothing

End Sub

Any reference to the Selection property of the Excel Application object will result in Excel not terminating after xl is set to Nothing. Obviously I could refrain from using Selection, but what if I can't do without? Any ideas?

Cheers,

Nick.

P.S. I'm using VB 5.0 with Excel 97 on Windows NT 4.0.