Delete a module

 2000-02-05    VBE    0    48

When you want to delete a module by code, you can use the macro below:

Sub DeleteVBComponent(ByVal wb As Workbook, ByVal CompName As String)
' requires a reference to the Microsoft Visual Basic Extensibility library
' deletes the vbcomponent named CompName from wb
    Application.DisplayAlerts = False
    On Error Resume Next ' ignores any errors
    wb.VBProject.VBComponents.Remove wb.VBProject.VBComponents(CompName) 
    ' delete the component
    On Error GoTo 0
    Application.DisplayAlerts = True
End Sub
DeleteVBComponent ActiveWorkbook, "TestModule"

Leave a comment:

Your comment will only be published after it has been moderated and found spam free.
Your e-mail address will only be used to display your Gravatar.