Modul in eine andere offene Mappe kopieren
30.01.2019 14:57:58
Alex
irgendwie erstellt dieser code nicht die strTempFile Datei. Und wenn ich versuche sie manuell wird nichts importiert.
SourceWB und TargetWB sind die richtig.
Was mache ich falsch?
CopyModule ThisWorkbook, "Modul1", Workbooks(MName)
Sub CopyModule(SourceWB As Workbook, strModuleName As String, TargetWB As Workbook)
' requires a reference to the Microsoft Visual Basic Extensibility library
Dim strFolder As String, strTempFile As String
strFolder = SourceWB.Path
If Len(strFolder) = 0 Then strFolder = CurDir
strFolder = strFolder & "\"
strTempFile = strFolder & "~test.bas"
On Error Resume Next
SourceWB.VBProject.VBComponents(strModuleName).Export strTempFile
TargetWB.VBProject.VBComponents.Import strTempFile
Kill strTempFile
On Error GoTo 0
End Sub
Anzeige