How to delete the leftover Excel object using VB.NET / Vb.NET delete Excel from memory
Excel runtimes that remain after the program is a nemesis. Many times this might be due to the leftover Excel objects in the program that causes Excel to remain in memory even after Application.Quit. Workbooks that are modified and left open often causes this problem. We have tried out one method to get rid of the Excel in memory using Vb.NET. We assumed that the programs that used Excel has been terminated and if any Excel remains in the memory it should be of the ‘legitimate’ application that the user has opened or the left over Excel.
We checked the presence of Title for Excel Application, which was present in all cases for the open instance of Excel. Left over instances didn’t had the title. The following code ‘kills’ the instances of Excel in memory that don’t have a WindowTitle.
Public Sub KillUnusedExcelProcess()
Dim oXlProcess As Process() = Process.GetProcessesByName("Excel")
For Each oXLP As Process In oXlProcess
If Len(oXLP.MainWindowTitle) = 0 Then
Try if it works for you and post your suggestions or modifications
Keywords : automation does not close microsoft excel, Application.Quit not closing Excel