Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

Excel File Closing

$
0
0

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.


Viewing all articles
Browse latest Browse all 3509

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>