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
Example:
DeleteVBComponent ActiveWorkbook, "TestModule"
Nessun commento:
Posta un commento