So, habe jetzt mal ein Stück PgmCode...
27.01.2010 18:44:48
Luc:-?
...aus einem PgmGenerator, der genau solche Prozeduren erzeugt, als Beispiel (!) kopiert, damit du nicht soviel suchen musst. Die VBE-Hilfe solltest du aber trotzdem lesen!
With ActiveWorkbook
If bsx Then
With .VBProject.VBComponents(1).CodeModule
If .Find("Sub Workbook_Open", 1, 1, .CountOfLines, 1) Then
If .Find("Protect", .ProcStartLine("Workbook_Open", vbext_pk_Proc), _
1, .ProcCountLines("Workbook_Open", vbext_pk_Proc), 1) Then
For i = .ProcStartLine("Workbook_Open", vbext_pk_Proc) To _
.ProcStartLine("Workbook_Open", vbext_pk_Proc) + _
.ProcCountLines("Workbook_Open", vbext_pk_Proc) - 1
If InStr(.Lines(i, 1), "Protect") > 0 And (pw = "" Or _
InStr(LCase(.Lines(i, 1)), pw) = 0) Then
.ReplaceLine i, vbTab & "Rem ----- Line replaced by XXX " & _
Date & " -----" & vbLf & vbTab & "Me.Protect """ & pw & """"
Exit For
End If
Next i
Else
For i = .ProcStartLine("Workbook_Open", vbext_pk_Proc) To _
.ProcStartLine("Workbook_Open", vbext_pk_Proc) + _
.ProcCountLines("Workbook_Open", vbext_pk_Proc) - 1
If InStr(.Lines(i, 1), "Sub ") > 0 Then
.InsertLines i + 1, vbTab & "Rem ----- Line inserted by XXX " & _
Date & " -----" & vbLf & vbTab & "Me.Protect """ & pw & """"
Exit For
End If
Next i
End If
Else: .ReplaceLine .CreateEventProc("Open", "Workbook") + 1, vbTab & _
"Rem ----- Procedure generated by XXX " & Date & " -----" & _
vbLf & vbTab & "Me.Protect """ & pw & """"
End If
End With
End If
With .VBProject.VBComponents
.Add(vbext_ct_StdModule).Name = "xxModul"
Set c = .Item("xxModul")
With c.CodeModule
.InsertLines .CountOfLines + 1, _
"Rem ----- Module installed by XXX " & Date & _
" © CyWorXxl.FXss -----" & vbLf
End With
End With
End With
Die Textplatzhalter XXX und Namen wirst du ja sicher individuell festlegen wollen. Ist ja alles nur ein Vorschlag/Bsp.
Gruß Luc :-?