This project has moved and is read-only. For the latest updates, please go here.

Security Settings seems to be Ignored

Mar 30, 2012 at 9:27 PM


not sure it's a bug but even if macros are disabled in Office (Access, Excel, Word...), my function "workbook_open" is still executed...  Weird isn't it..

I tried to set the property AutomationSecurity to ForceDisable but unfortunately it blocks access to the VBA object model.

Any solution?




PS: great code by the way :) Very useful!

Mar 31, 2012 at 4:20 AM


Accessing the COM Automation from all the office products is different to Macros, Macros means code inside of documents written in VBA.
I'm not sure what you want. Can you explaine a little bit more?


Mar 31, 2012 at 9:23 AM

Thx for your answer seb :).

Here is my use case: I have to estimate the complexity of tons of Office documents stored on a network share. Instead of opening all of them one after the other, I'm going to use a .NET app able to open this documents, analyse it, calculates metrics and finally close it... However, for some unknown reasons when i open a document using NETOffice, macros are enabled and thus functions like Workbook_Open are called... I don't want that to happen because they may modify the data or worse display a msgbox that would block my app...

Is there a way to disable macros and still have access to VBOM?



Apr 2, 2012 at 6:16 PM
Edited Apr 2, 2012 at 6:26 PM


first: sorry for the delay (weekend)

sounds strange! i have a lot of questions..., the documents are different? all .xls , xlsx or .xlsm? which excel version is ??? let me explain... macros in excel... stupid functions, awaiting parameters, calculate a litle bit with the parameters and return a result. true macros has no relationship to VBA Projects model. otherwise you can use VBA functions in an attached VBA project as macros, this is a special service. a lot of more what i have to say about them but anyway.... the exceuted vba code in the open workbooks causes trouble? You need a kind of safe mode, start the application just for automation. this is not easy, please remember, NetOffice is an 1:1 Wrapper, no own ideas inside, only a little bit xtra stuff. its a logical office problem here.  lets try the easiest way for you:

Excel.Application application = new Excel.Application();
application.EnableEvents = false; // excel dont throw any events for VBA now.


Apr 3, 2012 at 8:32 AM


I'm using MS Office 2010 SP1 with latest CU. It's strange, i don't understand why the security context defined in Office is not used when opening a doc though automation...

How can i disable macros in Access/PowerPoint & Word? As fas as i can see the "EnableFunction" property does not exist in the Word/PowerPoint/Access's VBOM :)...

Moreover, I'm getting BSOD each time i try to release several types of handle (Excel.Application and then Access.application)


            dynamic appA = new NetOffice.AccessApi.Application();
            appA.OpenCurrentDatabase(@"D:\XLS\Facture_IHM.mdb", true);

            dynamic = new NetOffice.ExcelApi.Application();

            appA.Quit(); <= Causes BSOD!!!


Apr 5, 2012 at 4:40 AM

i cant reproduce an error. its possible you do a test with the interop assemblies?
if the same error occurs you have an access issue.