I have the following code in a userform to delete "Module 2" and it works - sometimes. (I "borrowed" this code from a website, I don't remember which one)
Immediately following this code, the file saves and sends itself.
My issue is that If I stop the code BEFORE the Save & Send, Module 2 goes away - as it should. However, if I let it run the file saves itself WITH Module 2 still there!
Any ideas?
Code:
DeleteVBComponent ThisWorkbook, "Module2"
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
My issue is that If I stop the code BEFORE the Save & Send, Module 2 goes away - as it should. However, if I let it run the file saves itself WITH Module 2 still there!
Any ideas?