Question posted 2011 · +9 upvotes
How to check from .net code whether “Trust access to the VBA project object model” is enabled or not for an Excel application?
Manually I can check it from Excel application- File>Options>Trust Center>Trust Center Settings>Macro Settings>Trust access to the VBA project object model

Accepted answer +16 upvotes
The short answer is that you cannot directly access this setting using the Excel object model (i.e. through PIAs). However, instead, you can check this setting from the registry in the following location (here I assume that you’re using Office 2007 – version 12.0):
HKEY_CURRENT_USERSoftwareMicrosoftOffice12.0ExcelSecurityAccessVBOM
this is a DWORD that will be 0 or 1 depending on whether the “Trust access to VBA Object Model” is enabled.
However, this setting can be overriden by another registry key located at:
HKEY_LOCAL_MACHINESoftwareMicrosoftOffice12.0ExcelSecurityAccessVBOM
this is again a DWORD, however, if this value is 0 this means that no matter what the HKCU value is set to, then access to the VBOM will be denied. If the value in HKLM is 1 or missing, then the HKCU key will control the access to the VBOM.
Therefore, all you need to do is to check these two keys via the Registry methods in .NET.
2 code variants in this answer
- Variant 1 — 1 lines, starts with
HKEY_CURRENT_USERSoftwareMicrosoftOffice12.0ExcelSecu… - Variant 2 — 1 lines, starts with
HKEY_LOCAL_MACHINESoftwareMicrosoftOffice12.0ExcelSec…
Top excel-vba Q&A (6)
- How to clear the entire array? +58 (2010)
- How to change Format of a Cell to Text using VBA +55 (2011)
- Download attachment from Outlook and Open in Excel +43 (2012)
- Can a VBA function in Excel return a range? +36 (2009)
- 2 Dimensional array from range +34 (2013)
- Hiding an Excel worksheet with VBA +33 (2009)
excel-vba solutions on this site
— top 20%.