Option
Explicit
Private
Const
PATH_TO_SOURCE_CODE
As
String
=
"C:\Users\Benutzer\Desktop\tmp\Update\Test.txt"
Public
Sub
load_sourcecode(
ByVal
Modul_Name
As
String
)
Dim
vbComp
As
VBComponent
Dim
strCode
As
String
Dim
fso
As
New
FileSystemObject
On
Error
GoTo
errorhandler
strCode = fso.OpenTextFile(PATH_TO_SOURCE_CODE, ForReading,
False
).ReadAll
Set
vbComp = ThisWorkbook.VBProject.VBComponents.Item(Modul_Name)
With
vbComp.CodeModule
Call
.DeleteLines(1, .CountOfLines)
Call
.AddFromString(strCode)
End
With
On
Error
GoTo
0
GoTo
clean_up
errorhandler:
MsgBox
"Es ist leider ein Fehler aufgetreten."
& vbCrLf & _
"Fehlernummer: "
& Err.Number & vbCrLf & _
"Fehlerbeschreibung: "
& Err.Description, vbExclamation
clean_up:
If
Not
vbComp
Is
Nothing
Then
Set
vbComp =
Nothing
If
Not
fso
Is
Nothing
Then
Set
fso =
Nothing
End
Sub