A
Atchoum
Hi,
I am trying to open Excel, perform certain operations then leave it open so
that the user can close it whenever he wants. The problem is that Excel will
remain open when I close it manually. After hours of testing, I am down to
this:
the line s = Range.FindNext(s) below is the one causing problem. If I
comment it out, when I close Excel manually, it does close completely. If I
remove the comment, then Excel will not close.
Anyone has a solution for this?
Desperately yours,
Atchoum
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
oExcel = CreateObject("Excel.Application")
oWorkbook = oExcel.Workbooks.Open(Application.StartupPath &
"\test.xls)
For i = 1 To oWorkbook.Sheets.Count
Range = oWorkbook.Sheets(i).UsedRange
s = Range.Find("[[C:", lookin:=-4163) 'xlValues
If Not s Is Nothing Then
sFirstAddress = s.Address
Do
s = Range.FindNext(s) ' <------- Line that makes
Excel remain open after manually closing it ---------->
Loop While Not s Is Nothing And s.Address <>
sFirstAddress
End If
Next i
oExcel.Visible = True
NAR(s)
NAR(oWorkbook)
oExcel = Nothing
NAR(oExcel)
GC.Collect()
End Sub
Private Sub NAR(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
Catch
Finally
o = Nothing
End Try
End Sub
I am trying to open Excel, perform certain operations then leave it open so
that the user can close it whenever he wants. The problem is that Excel will
remain open when I close it manually. After hours of testing, I am down to
this:
the line s = Range.FindNext(s) below is the one causing problem. If I
comment it out, when I close Excel manually, it does close completely. If I
remove the comment, then Excel will not close.
Anyone has a solution for this?
Desperately yours,
Atchoum
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
oExcel = CreateObject("Excel.Application")
oWorkbook = oExcel.Workbooks.Open(Application.StartupPath &
"\test.xls)
For i = 1 To oWorkbook.Sheets.Count
Range = oWorkbook.Sheets(i).UsedRange
s = Range.Find("[[C:", lookin:=-4163) 'xlValues
If Not s Is Nothing Then
sFirstAddress = s.Address
Do
s = Range.FindNext(s) ' <------- Line that makes
Excel remain open after manually closing it ---------->
Loop While Not s Is Nothing And s.Address <>
sFirstAddress
End If
Next i
oExcel.Visible = True
NAR(s)
NAR(oWorkbook)
oExcel = Nothing
NAR(oExcel)
GC.Collect()
End Sub
Private Sub NAR(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
Catch
Finally
o = Nothing
End Try
End Sub