Yes.
Sub
Dim WBCodeMod As Object
Dim StartLine As Integer, LineCount As Long, CodeLine As Long
' Create an object reference for the Code Module
Set WBCodeMod = [Workbook].VBProject.VBComponents("ThisWorkbook").CodeModule
End Sub
Sub
DeleteProcedure WBCodeMod, "procedure name"
Private Sub DeleteProcedure(CodeMod As Object, ProcDec As String)
' Deletes a specified procedure in a module
Dim StartLine As Long, NumLines As Long
' Determine the first line of the procedure
StartLine = CodeMod.ProcStartLine(ProcDec, 0)
' Determine the number of lines in the procedure
NumLines = CodeMod.ProcCountLines(ProcDec, 0)
' Delete the procedure's lines
CodeMod.DeleteLines StartLine, NumLines
End Sub
---------------
You'll have to modify this to your particular situation, but this is the general idea.
Mike
Sub DeleteModule()
Dim VBComp As VBComponent
Set VBComp = ThisWorkbook.VBProject.VBComponents("NewModule")
ThisWorkbook.VBProject.VBComponents.Remove VBComp
End Sub
You cannot delete the ThisWorkbook code module, or a sheet code module, or a chart code module.