Sam Oshanter
Sam Oshanter

Reputation: 41

Excel XLSTART problem with C#/.Net

I have a C# application (.Net 1.1) and use excel interop to display some reoprts. It turns out that when opening an excel workbook the files in XLSTART are not read, it's as if the /automation command line switch has been run.

Is there any way to enable XLSTART when launching an XLS sheet from C#?

Upvotes: 4

Views: 798

Answers (2)

Dirk Vollmar
Dirk Vollmar

Reputation: 176179

This behavior is by design. You can load the add-ins in the XLSTART folder yourself as described by Microsoft:

Add-ins do not load when using the CreateObject command in Excel

Another option that you have is to start Excel using Process.Start and then an automation object from the running instance by calling the AccessibleObjectFromWindow function.

Sample code how to do this in C# or VB can be found in a related question:

How to use use late binding to get excel instance?

Please note that you don't have to use late binding as in the example given. Modifying the sample like this should give you a strongly-typed Excel.Application object:

Excel.Application xlApp = ptr.GetType().InvokeMember("Application",
    BindingFlags.GetProperty, null, ptr, null);

Upvotes: 2

YWE
YWE

Reputation: 2909

Because it uses interop, it opens Excel as an automation server. It is the same thing as using the /automation switch. When Excel is opened that way, all automatically opened files and auto-run macros are disabled.

Upvotes: 0

Related Questions