wie lässt sich mittels VBA eine Prozedur löschen und ersetzen, ohne dass gleich das gesamte Modul gelöscht wird.
Also:
Sub hans
[A1]="Torwart"
End Sub
löschen und ersetzen durch
Sub hans
[A1]="Stürmer"
End Sub
Gruß
Rolf H.
Sub hans
[A1]="Torwart"
End Sub
Sub hans
[A1]="Stürmer"
End Sub
Sub aaa()
Dim vbc
Dim iStart, iAnzahl
Const sProc As String = "hans"
For Each vbc In ThisWorkbook.VBProject.VBComponents
If vbc.Type = 1 Then
On Error Resume Next
With vbc.codemodule
iStart = .ProcStartLine(sProc, vbext_pk_Proc)
iAnzahl = .ProcCountLines(sProc, vbext_pk_Proc)
If Err.Number = 0 Then
.DeleteLines iStart, iAnzahl
.InsertLines iStart, ""
.InsertLines iStart + 1, "Sub hans()"
.InsertLines iStart + 2, " [A1]=""Stürmer"""
.InsertLines iStart + 3, "End Sub"
.InsertLines iStart + 4, ""
End If
End With
On Error GoTo 0
End If
Next
End Sub
Sub yyy()
Dim vbc As Object
Dim sCode As String
Application.ScreenUpdating = False
sCode = "Sub Meldung()" & vbLf
sCode = sCode & " MsgBox ""Hallo Welt!""" & vbLf
sCode = sCode & "End Sub"
Set vbc = ActiveWorkbook.VBProject.VBComponents("Modul1")
'oder neues Modul:
'Set vbc = ActiveWorkbook.VBProject.VBComponents.Add(1)
vbc.codemodule.addfromstring sCode
End Sub