Excel Interop to open excel with macros disabled

Nishant picture Nishant · May 2, 2012 · Viewed 8.7k times · Source

Is there a way in C# to switch off macros in excel before loading an excel file. I am loading the excel file using Excel Interop. All I can see is solutions for VB.NET.

Thanks Nishant

Answer

John Koerner picture John Koerner · May 2, 2012

I think you can just set it on your Excel Application:

Excel.Application xapp = new Excel.Application();
xapp.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable;