0

This is my first question and I'm horribly scared my answer could already be on some other post. But I've searched for hours and I really can't get my head around it.

So here's the thing.

I'm working on a windows form that, very simplistically, has to open certain workbooks and run macros inside these workbooks.

The macros in these workbooks use certain functions that do not belong to standard excel libraries. I work in a bank and we have some proprietary functions and add-ins which are loaded every time we open certain exe files.

I can launch an excel application through:

Microsoft.Office.Interop.Excel.Application xlApp = 
            new Microsoft.Office.Interop.Excel.Application();

but this calls the normal excel. How can I add the libraries I need in this specific instance of excel?

The alternative solution is to launch excel with the libraries manually, using System.Diagnostics.Process.Start("CMD.exe","My fancy excel");

but this takes a huge amount of time, as a new instance has to be created for each workbook.

Any thoughts or clarifications needed?

Thank you all for your time, hope I was clear enough!

Behzad
  • 3,502
  • 4
  • 36
  • 63
  • Could you elaborate what you mean by libraries? Do you mean addins? What happens when you do when you run your code and open a workbook? Are the addins loaded? – dgorti Jul 15 '15 at 05:12
  • When I try to open a workbook the prompt to run the macro normally appears. But the macro stops working halfway through. This happens because inside the macro I have some lines like the following: application.Run("Certain_Function", Arg1, ..., ArgN) whose reference does not exist in a normal excel application instance. But the function does work if I open excel and load certain Add-ins. – ZeroReaction Jul 15 '15 at 05:46

1 Answers1

0

When starting Excel through automation, it won't load any add-ins. So you have to explicitly load the add-ins using:

  • Application.RegisterXLL (for .xll add-ins), or
  • AddIns.Add / AddIn.Installed = true (for .xla or .xlam add-ins).

Here is an older question on the topic: Loading addins when Excel is instantiated programmatically, and a related MSDN blog post: http://blogs.msdn.com/b/accelerating_things/archive/2010/09/16/loading-excel-add-ins-at-runtime.aspx and another Microsoft support article: https://support.microsoft.com/en-us/kb/213489.

Community
  • 1
  • 1
Govert
  • 16,387
  • 4
  • 60
  • 70
  • Thank you! I think that's exactly what I was looking for. I'll keep you posted! – ZeroReaction Jul 15 '15 at 09:22
  • Hi Govert, I was able to load a certain add-in in my automation OLE object, which is fantastic! Do you think it is possible to add single .dll files to this object as well? Thanks! – ZeroReaction Jul 16 '15 at 02:26