Releasing Excel Object from Memory / Task manager in .NET
Public Function Excel_Memory_Release(ByRef xla As Object, ByRef xlw As Object, ByRef xls As Object, Optional ByVal pSaveChanges As Boolean = True) As Boolean
If Not IsNothing(xla) Then xla.DisplayAlerts = False
If Not IsNothing(xlw) Then
If Not pSaveChanges Then
xlw.Close(savechanges:=False)
Else
xlw.close()
End If
End If
xls = Nothing
xlw = Nothing
If Not IsNothing(xla) Then xla.Quit()
If Not IsNothing(xla) Then System.Runtime.InteropServices.Marshal.ReleaseComObject(xla)
xla = Nothing
GC.Collect()
Return True
End Function
If Not IsNothing(xla) Then xla.DisplayAlerts = False
If Not IsNothing(xlw) Then
If Not pSaveChanges Then
xlw.Close(savechanges:=False)
Else
xlw.close()
End If
End If
xls = Nothing
xlw = Nothing
If Not IsNothing(xla) Then xla.Quit()
If Not IsNothing(xla) Then System.Runtime.InteropServices.Marshal.ReleaseComObject(xla)
xla = Nothing
GC.Collect()
Return True
End Function
No comments:
Post a Comment