Search code snippets, questions, articles...

Close all excel process using C#

The code can be used to close all the excel processes running using C# code.
public async Task<bool> closeExcelProcesses()
{
    try
    {
        System.Diagnostics.Process[] process=System.Diagnostics.Process.GetProcessesByName("Excel");
        foreach (System.Diagnostics.Process p in process)
        {
            if (!string.IsNullOrEmpty(p.ProcessName))
            {
                p.Kill();
            }
        }
        TraceService("ALL EXCEL PROCESSES CLOSED");
        return true;
    }
    catch(Exception ex)
    {
        TraceService("ERROR IN CLOSING EXCEL PROCESSES");
        return false;
    }
}
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool
Was this helpful?
0 Comments