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

后端 未结 4 1167
情深已故
情深已故 2020-12-16 00:47

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

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-16 01:02

    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

提交回复
热议问题