Hallo Torsten,
es folgt ein Code-Beispiel, das glaube ich hier vom Forum ist:
(es ist zwar eine Neuerstellung von Code, ändern aber analog).
Sub test()
Dim CP As Object
' CodePane für Tabelle2 finden
For Each CP In Application.VBE.CodePanes
If CP.codemodule.Name = "Tabelle2" Then
Set Application.VBE.ActiveCodePane = CP
End If
Next
' Code einfügen
With Application.VBE.ActiveCodePane.codemodule
.InsertLines .countoflines + 1, "Private Sub CommandButton1_Click()"
.InsertLines .countoflines + 1, " MsgBox ""Ich bin Code für Tabelle 2"""
.InsertLines .countoflines + 1, "End Sub"
End With
End Sub