2

Using the following code I can run Excel from within C#:

System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "cmd.exe";
p.Start();

Can I make Excel start hidden or minimized using any command line parameters?

(Edit: Tried p.StartInfo.WindowStyle and it had no effect.)

I need to start Excel without using COM because when starting Excel over COM, none of the XLA add-ins are loaded.

chiccodoro
  • 14,407
  • 19
  • 87
  • 130

1 Answers1

6

You can set the WindowStyle property to Minimized or Hidden. Like the following:

ProcessStartInfo p = new ProcessStartInfo("excel.exe");
p.WindowStyle = ProcessWindowStyle.Minimized;
Process.Start(p);
Garett
  • 16,632
  • 5
  • 55
  • 63
  • thanks for the answer. Unfortunately it seems to have no effect at all (BTW: It's `p.StartInfo.WindowStyle`, not `p.WindowStyle`) – chiccodoro Sep 16 '10 at 06:23
  • This code was taken from a working program. Notice the subtle differences between this and your code. It doesn't create an instance of the `Process` class. Rather, it uses `ProcessStartInfo` class, and passes it to the static `Start` method of `Process`. I tested it with office 2007 (on Windows XP) and 2010 (on Windows 7). – Garett Sep 16 '10 at 13:14
  • ... this did it! Although I don't understand the technical difference between `Process.Start(new ProcessStartInfo(FooBar))` and `new Process() { StartInfo.Foo = Bar }.Start()`, your version works well for me. – chiccodoro Sep 17 '10 at 07:09
  • Since you've been using this code successfully, could you assist me with another issue I'm facing now? http://stackoverflow.com/questions/3736550/add-in-makes-excel-crash-when-starting-minimized – chiccodoro Sep 17 '10 at 15:08