If you want to use the vba code to delete the vba code in the worksheet, you must first introduce a control in excel, the steps are as follows:
1. For the EXCEL 2003 version, in the VBE, Tools-Reference-Microsoft Visual Basic For Application Extensibility 5.3
(Different versions, Microsoft Visual Basic For Application Extensibility 5.3 may be written differently)
2. Select the toolbar-->Macro-->Security...-->Reliable Publisher-->Trust access to "Visual Basic Project"
3. Next, if you just want to delete the code in all worksheets, you can enter the code in the VBA window:
Sub Remove_some_vba_code()
Dim activeIDE As Object 'VBProject
Set activeIDE = ActiveWorkbook.VBProject
Dim Element As VBComponent
Dim LineCount As Integer
For Each Element In activeIDE.VBComponents
If Left(Element.Name, 5) = "Sheet" Then
LineCount = Element.CodeModule.CountOfLines
Element.CodeModule.DeleteLines 1, LineCount
End If
Next
End Sub
If you want to delete all the code, delete the judgment statement in the middle
Sub Remove_all_vba_code()
Dim activeIDE As Object 'VBProject
Set activeIDE = ActiveWorkbook.VBProject
Dim Element As VBComponent
Dim LineCount As Integer
For Each Element In activeIDE.VBComponents
LineCount = Element.CodeModule.CountOfLines
Element.CodeModule.DeleteLines 1, LineCount
Next
End Sub