none
Excel 2010 Run time error 1004. Programatic access to visual basic project is not trusted

    Question

  • Hi Developers,

    I have a macro to delete all VBA code and modules. This macro works fine in excel 2003 but in 2010 it opens only in protected view and when i select edit option it throws error "Excel 2010 Run time error 1004. Programatic access to visual basic project is not trusted"

    Due to security reason i don't want to maunally check (enable) programatic access to vb project trusted.

    This error doesn't pop up in excel 2003 than why it pop up in 2010. Below is the code

    Sub SupprimeToutCodeEtFormulaire()

    Dim VBComp As Object

    Dim VBComps As Object

    Set VBComps = ActiveWorkbook.VBProject.VBComponents ' this line throws error

    For Each VBComp In VBComps

    Select Case VBComp.Type

    Case 100

    With VBComp.CodeModule

    .DeleteLines 1, .CountOfLines

    End With

    Case Else

    VBComps.Remove VBComp

    End Select

    Next VBComp

    End Sub

    Monday, August 27, 2012 2:11 PM

Answers