Hi.
It seems that the Office engine is keeping track of the last used value of the registry value and writing it on exit.
These are two different articles discussing the same (or similar behavior) I just found googling a bit:
MSDN Blogs > cristib > VBA - How to programmatically enable access to the VBA object model using macros
Quote:
It seems that the Office application will remember what was the value for this key when it first started. If while the application is running you attempt to modify the 'AccessVBOM' key by any method (macro, script, manually editing the key ...etc), except for going in 'Options' > 'Trust Center' > 'Trust Center Setting' > 'Macro Settings', your change will be discarded on exit. Since you need to exit the application and load it again for the setting to become effective, you cannot programmatically enable / disable access to VB object model.
RE: Enabling Turst access to Visual Basic Projects
Quote:
It is possible to Enable Trust to Visual Basic Project from VBA code.
It can be modifed through regedit.exe. It is called AccessVBOM, which can
also be modified through VBA code. However, closing Excel will set the
AccessVBOM value back to the level that is indicated in the "Trust access to
Visual Basic Project" checkbox
A possible workaround might be delaying the last operation that sets it to zero, scheduling it to be run after a set amount of time or to wait for the Office engine to be unloaded. Otherwise, You may try to reset it to zero through the object model provided by the office engine (if available) rather than direct access to the registry value.
Regards,
Daniele.