PDA

View Full Version : Solved: Trust Access To... question



johnske
09-27-2006, 04:16 PM
I only have Office 2k so I can't test this myself... What I want to know is in 2002 and up, if the 'Trust Access to Visual Basic Project' is left unchecked, will using late binding allow this code (specifically) to run?

Note: Caution!! This deletes ALL VBA code in the workbook
Sub DeleteAllVBA()
'use late binding so no reference is needed
Dim Component As Object
For Each Component In ThisWorkbook.VBProject.VBComponents
Select Case Component.Type
Case 1, 2, 3
ThisWorkbook.VBProject.VBComponents.Remove Component
Case Else
With Component.CodeModule
.DeleteLines 1, .CountOfLines
End With
End Select
Next
End Sub
TIA,
John :)

Ken Puls
09-27-2006, 04:19 PM
Nope. Works fine with the box checked, but errors if the box is unchecked.

:)

johnske
09-27-2006, 04:21 PM
OK, thanx Ken (that's what I thought :))