Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check from .net code whether "Trust access to the VBA project object model" is enabled or not for an Excel application?

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

enter image description here

like image 667
Kushal Waikar Avatar asked Mar 14 '11 15:03

Kushal Waikar


1 Answers

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

like image 64
Brad Avatar answered Oct 12 '22 11:10

Brad