Hi All,
I want to close the Excel file using program that has been already opened by the user by double clicking.
This is the Codesnippet i have wrote.
List<string> Proc = new List<string>();
List<string> ProcID = new List<string>();
Process[] processes;
string procName = "Excel";
processes = Process.GetProcessesByName(procName);
foreach (Process proc in processes)
{
Proc.Add(proc.MainWindowTitle);
ProcID.Add(proc.Id.ToString());
}
int procID = System.Convert.ToInt32(ProcID[0]);
Process tempProc = Process.GetProcessById(procID);
tempProc.CloseMainWindow();
tempProc.WaitForExit();
This works pretty well for applications which creates separate instances like notepad.
I am facing the problem in excel as multiple sheets runs in a single instance.
So killing the process is not working.
Please someone help me with this.