3

I am creating an instance of Microsoft Excel in a .NET application (WPF if it matters) and I am embedding it inside like this :

        var excelType = Type.GetTypeFromProgID("Excel.Application");
        var excelObj = Activator.CreateInstance(excelType);
        excelType.InvokeMember("Visible", BindingFlags.SetProperty, null, excelObj, new object[] { true }, ComCulture);
        var excelHwnd = new IntPtr((int)excelType.InvokeMember("Hwnd", BindingFlags.GetProperty, null, excelObj, new object[0], ComCulture));
        var managedWindowHwnd = new WindowInteropHelper(Application.Current.MainWindow).Handle;
        SetParent(excelHwnd, managedWindowHwnd);
        MoveWindow(excelHwnd, 0, 0, Convert.ToInt32(Width), Convert.ToInt32(Height), true);

All works except Excel does not load the add-ins installed. If I run Excel via the start menu it loads the add-ins.

I guess I need to specify some arguments to Excel to enable the add-ins loading. But I have no idea what/how...

Andrei Rînea
  • 20,288
  • 17
  • 117
  • 166
  • Why don't you just start a process? – chris6523 Apr 25 '12 at 09:13
  • Well we have a large app built around activating and embedding Excel like this and it would be difficult to change things. Starting a process helps load the addins but even so some addins crash on certain commands. I am hoping for a sqitch or some startup option that I can force into Excel.. – Andrei Rînea Apr 25 '12 at 09:32

1 Answers1

0

you may do this manually using interop, you may refer to my post at Get the excel cell address from a UDF to get handle to excel's Application object. Once you have application you can manually enable addins by looping through application.AddIns and and application.ComAddIns and seting installed/connect property to true for each item

Community
  • 1
  • 1
Brijesh Mishra
  • 2,738
  • 1
  • 21
  • 36