
Originally Posted by
Andy Pope
I don't think there is a property to test.
Instead you can create your own function which uses error trapping.
Function VBATrustedAccess() As Boolean
'
On Error Resume Next
VBATrustedAccess = (Application.VBE.VBProjects.Count) > 0
Exit Function
End Function
Sub Test()
If VBATrustedAccess() Then
MsgBox "Access Granted"
Else
MsgBox "No Access to VBA"
End If
End Sub
Appears to work with limited testing.
If the workbook that contains the code above is closed, then re-opened in the same Excel session (meaning don't Exit Excel) the check won't work. When I put it in my workbook Open event it worked the first time but when I closed the file and then re-opened it in the same Excel session the Workbook_Open event didn't even fire off!
Private Sub Workbook_Open()
If VBATrustedAccess() Then
MsgBox "Access Granted"
Else
MsgBox "No Access to VBA"
End If
End Sub
Excel 2010 in Windows 7
Bookmarks