BUY EXCEL BOOKS ONLINE: 1. VBA & Macros      2. VBA for Modelers      3. Excel 2013 VBA and Macros     
4. Excel VBA for Dummies      5. Excel with VBA & .NET      6. Mastering VBA      7. Excel 2013 Programming

Delete or Remove Event Macros, VBA Code and Module

Brief Description: 
This macro will delete all event macros, sub routines and user defined functions from Active workbook. This requires reference to "Microsoft Visual Basic for Applications Extensibility 5.3" and trusted access to VBA project model.(Developer --> Macro security --> Trust access to VBA project model).

Sub RemoveAllVBACode()
'This code will delete ALL VBA code in a VBProject.
On Error GoTo Errorhand
    Dim VBProj As VBIDE.VBProject
    Dim VBComp As VBIDE.VBComponent
    Dim CodeMod As VBIDE.CodeModule
        Set VBProj = ActiveWorkbook.VBProject
        For Each VBComp In VBProj.VBComponents
            If VBComp.Type = vbext_ct_Document Then
                Set CodeMod = VBComp.CodeModule
                With CodeMod
                    .DeleteLines 1, .CountOfLines
                End With
                VBProj.VBComponents.Remove VBComp
            End If
        Next VBComp
    Exit Sub
        MsgBox "Go to Developer Tab --> Macro Security and enable ""Trust access to VBA project object model."" and then try again."
On Error GoTo 0
End Sub
CCNA Training said...

Thanks for the article it was interesting