AW: In Worksheet_Deactivate() Code per Modul schreiben
08.10.2007 23:11:00
Luschi
Hallo Oliver,
da der Vbe-Befehl "CreateEventProc" die gewünschte Prozedur neu erzeugt, ohne zu testen, ob es die Prozezur schon gibt, habe ich das Beispiel mal so erweitert, daß eine schon vorhandene Prozedur vorher gelöscht wird.
Dazu ist dann allerdings der Verweis 'Microsoft Visual Basic fie Applications Extensibility 5.x' _
erforderlich.
Sub Makro_einfuegen()
Dim x1 As Long, x2 As Long, x3 As Long
With ActiveWorkbook.VBProject.VBComponents("Tabelle1").CodeModule
On Error GoTo error_1
x1 = .ProcBodyLine("Worksheet_SelectionChange", vbext_pk_Proc)
On Error GoTo 0
If x1 > 0 Then
x2 = .ProcCountLines("Worksheet_SelectionChange", vbext_pk_Proc)
.DeleteLines x1, (x2 - x1 + 2)
End If
continue_1:
x1 = .CreateEventProc("SelectionChange", "Worksheet")
MsgBox x1
.InsertLines x1 + 1, "'dieses Makro wurde per Makro eingefügt"
.InsertLines x1 + 2, "MsgBox ""Hallo, Hallo !!!"""
.InsertLines x1 + 3, "MsgBox ""Ballo, Ballo !!!"""
.InsertLines x1 + 4, "MsgBox ""Knallo, Knallo !!!"""
End With
Exit Sub
error_1:
On Error GoTo 0
GoTo continue_1
End Sub
Gruß von Luschi
aus klein-Paris