AW: In Worksheet_Deactivate() Code per Modul schre
12.10.2007 22:52:03
OliverBreith
habe doch noch einen Bug in deinem Code gefunden; habe es nun wie folgt verbessert. Läuft nun tadellos.
Danke nochmal
Sub Makro_in_Workbook_zufügen()
'Fügt in erste Tabelle des Workbooks ein Macro in Deactivate_Ereignis
Dim x As Variant, x1 As Long, x2 As Long, Anzahl_der_Zeilen As Long
With ActiveWorkbook.VBProject.VBComponents("DieseArbeitsmappe").CodeModule
On Error GoTo error_1
x1 = .ProcBodyLine("Workbook_Deactivate", vbext_pk_Proc)
On Error GoTo 0
Anzahl_der_Zeilen = .CountOfLines
If x1 > 0 Then
x2 = .ProcBodyLine("Workbook_Deactivate", vbext_pk_Proc)
.DeleteLines 1, Anzahl_der_Zeilen
End If
continue_1:
x1 = .CreateEventProc("Deactivate", "Workbook")
.InsertLines x1 + 1, "'dieses Deactivate Makro wurde durch das Add-In per Makro eingefügt"
.InsertLines x1 + 2, "Datenbank_aktualisieren"
End With
Exit Sub
error_1:
On Error GoTo 0
GoTo continue_1
End Sub