views:

61

answers:

1

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.

+1  A: 

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
@Garett, thanks for the answer. Unfortunately it seems to have no effect at all (BTW: It's `p.StartInfo.WindowStyle`, not `p.WindowStyle`)
chiccodoro
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
Oh yes, you're right, let's give another try...
chiccodoro
... 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
@Garett: 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