Friday, February 15, 2013

VB.Net - Close Excel and Kill Process

How to make sure all Microsoft Excel processes are stopped after completing and Excel project using VB.net.

Here is a code example:

Dim app As new Application
Dim wb As Workbook
Dim sheet As new Worksheet

"Do Excel project"

sheet = Nothing
wb.Close()
app.Quit()
wb = Nothing
app = Nothing

For Each proc In System.Diagnostics.Process.GetProcessesByName("EXCEL")
    
     If proc.MainWindowTitle.Trim() = "" Then
          proc.Kill()
     End If

Next

This code will stop all Excel processes running on the machine.

No comments:

Post a Comment