|  

» Delete a module using VBA in Microsoft Excel

VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
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)
' 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

Example:
DeleteVBComponent ActiveWorkbook, "TestModule"


Rate This Tip
12 34 5
Rating: 3.33     Views: 19730
No comments have been submitted.
Click here to post comment
For Registered Users
Name
Comment Title
Comments