Danke Tobi
Sub Ersetzen()
With ThisWorkbook.VBProject.VBComponents("Tabelle1").CodeModule
iStart = .ProcBodyLine("CommandButton1_Click()", 0)
iCount = .ProcCountLines("CommandButton1_Click", 0)
.DeleteLines iStart, iCount
End With
'Dann soll neuer Code eingefügt werden (der natürlich dann ein bisschen durchdachter sein dürfte, als eine kleine Hallo-MsgBox...):
scode = "Private Sub CommandButton1_Click" & vbLf
scode = scode & " MsgBox ""Hallo!""" & vbLf
scode = scode & "End Sub"
ThisWorkbook.VBProject.VBComponents("basMain").CodeModule.AddFromString scode
End Sub