Monday, November 21, 2011

How to Kill or End Excel Programatically using VB.Net



This method will end or kill all the Excel files which is currently in taskmanger

Public Sub KillExcel()
        Try
            Dim lstProcess As New List(Of Process)

            lstProcess = Process.GetProcessesByName("EXCEL").ToList()
            lstProcess = lstProcess.Where(Function(P) P.MainWindowTitle = String.Empty).Select(Function(P) P).ToList()

            For Each pr As Process In lstProcess
                pr.Kill()
            Next
        Catch ex As Exception
            MessageBox.Show("Error on Killing Process")
        End Try   
     End Sub

I hope this article will be very helpful to all. Thanks for reading this article.

“Keep reading and share the knowledge”  
“Grow more trees to save the Earth”