Search code examples
c#.netwinformscomms-word

Kill particular instance of Winword


my application creates a new instance of winword embedded in a windows form.

new Microsoft.Office.Interop.Word.ApplicationClass()

Once the user finishes editing I close the window but the winword instance is still running in the background.

How can I kill that particular instance? I know how to kill all instances running on a machine but this isn't an option.


Solution

  • You need to call

    application.Quit()
    

    In your code.

    One thing I had to do on my system (it's an excel processing tool) is do a process kill if after the Quit things were still going on.

    var openedExcel = System.Diagnostics.Process.GetProcessesByName("EXCEL");
                if (openedExcel.Any())
                {
                    foreach (var excel in openedExcel)
                    {
                        try { excel.Kill(); }
                        catch { }
                    }
                }