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
This worked for me
Function VBATrusted() As Boolean
On Error Resume Next
VBATrusted = (Application.VBE.VBProjects.Count) > 0
End Function
Private Sub Workbook_Open()
If Not VBATrusted() Then
MsgBox "No Access to VB Project" & vbLf & _
"Please allow access in Trusted Sources" & vbLf & _
"File > Options > Trust Center > Trust Center Settings > Macro Settings > Trust Access..."
End If
End Sub
Source https://www.mrexcel.com/forum/excel-questions/659774-checking-if-trust-access-visual-basic-project-ticked.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With