I've been trying for a while, but I can not execute excel in the background.
What I want is to do a service that opens an excel book every 30 seconds and closes it later.
static void Main(string[] args)
{
while (true)
{
String ruta = Directory.GetCurrentDirectory().ToString();
Process p = new Process();
//Propiedades del proceso
p.StartInfo = new ProcessStartInfo("Exelcito.xlsm");
p.StartInfo.WorkingDirectory = ruta;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
//Iniciamos
p.Start();
Thread.Sleep(1000 * 5);//Carga del excel + ejecucion de macros
//Matamos
p.Kill();
Thread.Sleep(1000 * 25);
}
}
It happens that I need to run in the background and appear in the foreground, this has to run on the computer of one of the managers and it has to be in the background so as not to interrupt whatever it is doing.