Search code examples
c#excelvstooffice-addinsexcel-addins

C# Excel: Programmatically open and copy workbook while ignoring dependency


I'm currently trying to write an add-in that takes values from fileA and combine with file1. However fileA requires fileB and fileB requires fileC due to codes written with VBA by previous owner. I only require a certain sheet from fileA but when calling open to fileA, it will also open fileB and fileC.

Is there a way where I can open fileA or copy fileA without opening other files i.e. ignoring dependency? I tried searching online about it but most question and solution given are for files without dependency.

I am using Visual Studio 2017 with Excel 2013 and 2016 VSTO Add-In project.

Any help appreciated.

Note: I am not allowed to edit the VBA code and I do not need the values in fileA to be updated.


Solution

  • Try to open the file with AutomationSecurity disabled:

    Excel.Application app = new Excel.Application();
    app.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable;
    Workbook wb = app.Workbooks.Open(path);