0

We are encountering a strange issue when trying to automate Excel using the AutomationFactory in a Trust In Broswer Silverlight 5 application.

This code runs on the UI thread in Application_Startup:

dynamic excel = AutomationFactory.CreateObject("Excel.Application");
excel.Visible = false;
dynamic workbooks = excel.workbooks;
workbooks.Open(@"C:\temp\test.xlsm");
excel.Run("Test");

Note: The excel file is just a dummy excel file with a stub macro called Test() that does nothing. The file exists and is in the correct location.

The first time through a RuntimeBinderException is thrown at excel.Run("Test");

'object' does not contain a definition for 'Run'

Immediately after this, running the code again causes a RuntimeBinderException to be thrown earlier, at excel.Visible = false;

'object' does not contain a definition for 'Visible'

I checked the exact same code and setup on 2 coworkers machines and all of the statements executed correctly without exception.

I suspect something is happening behind the scenes in the AutomationFactory or with the COM objects or even with my VisualStudio setup, but I do not know enough about it to correctly debug or what to check. Perhaps something is amiss in DCOMCNFG?

Any ideas are appreciated.

Thank you,

Dan

zero_dev
  • 613
  • 9
  • 17
  • Maybe Excel is setup (as by default) to not trust macros when opening workbooks in the failing machines, but it's setup to trust them on your coworker's machines. – acelent Jun 18 '14 at 14:46
  • I have Excel enabled to trust all Macros(for now) and that unfortunately wasn't the solution. Is there a way to very the members of the underlying COM object? – zero_dev Jun 19 '14 at 18:59

0 Answers0