Got any Excel/VBA Questions? Free Excel Help
Sheet Event Code
Excel is rich in event code for both the Workbook Object and the Sheet Object. For example, the worksheet change event is possibly the most popular of Sheet Events.
The macro below can be used to delete Sheet Code based on the sheet code names supplied to the select case statement within the Sheets Collection loop . It's ideal to use when you need to copy Sheets from a Workbook but do not want the code to copy with the Sheets.
You will have to go to Tools>Macro>Security - Trusted Publishers and check Trust access to Visual Basic Editor before running the code
Sub DeleteSheetEventCode() ''Needs Reference Set To _ "Microsoft Visual Basic For Applications Extensibility" 'Tools>References. Dim sSheet As Object, strName As String For Each sSheet In Sheets Select Case UCase(sSheet.Name) Case "SHEET1", "SHEET2", "SHEET3" strName = sSheet.CodeName With ThisWorkbook.VBProject.VBComponents(strName).CodeModule .DeleteLines 1, .CountOfLines End With Case Else 'Whatever End Select Next sSheet End Sub
|Delete Module After Running VBA Code|
|Deleting Excel Named Ranges|
|Delete Excel Workbook Event Code|
Free Training Course: Lesson 1 - Excel Fundamentals