I am switching to a newer version of excel and some of my macros aren't working the same as before. The one I am stuck on now is how to delete components from modules that cannot be deleted such as the Workbook open code I have to begin prompts when I open the file, and also how to delete user forms. This is the code I was using that used to work just fine. I have a master file and then I open it, work in it, save as something else and when it gets saved I want to get rid of all the macros etc to cleanup the file etc. Any help??

Sub DeleteMacros()
'deletes workbook open code
Dim DeleteWBOpen As Object
Dim StartLine As Long
Dim HowManyLines As Long

Set DeleteWBOpen = ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
With DeleteWBOpen
StartLine = 1
HowManyLines = .CountOfLines
.DeleteLines StartLine, HowManyLines
End With

'Deletes modules
Dim VBComp As Object
Dim VBComp1 As Object

Set VBComp = ThisWorkbook.VBProject.VBComponents("UserForm1")
ThisWorkbook.VBProject.VBComponents.Remove VBComp
Set VBComp1 = ThisWorkbook.VBProject.VBComponents("UserForm2")
ThisWorkbook.VBProject.VBComponents.Remove VBComp1

End Sub