Hoffi hatte geholfen, funktionert auch das man das Modul kopierenkann.
Dies passiert allerdings mit einer neuen Mappe, ich möchte gern eine bestehende
Mappe, im Verzeichnis liegt z.b. "C:\Muster\Test.xls" darin das Modul kopieren.
Ich fummel gerade wieder einen "Wolf", habe schon viel verstanden, krieg das wohl nicht hin.
Hier das Makro:
Sub NeueMappe()
Dim wkb As Workbook
Dim sFile As String
Dim sPath As String
Dim intIndex As Integer, bolgefunden As Boolean
Application.ScreenUpdating = False
sFile = "C:\Muster\Test.xls"
sPath = "C:\Muster\temp.bas"
ThisWorkbook.VBProject.VBComponents("modPW").Export sPath
''Set wkb = Workbooks.Add(1)
Application.VBE.MainWindow.Visible = True
With wkb.VBProject.VBComponents(wkb.CodeName).CodeModule
.InsertLines 3, "
Private Sub Workbook_Open()"
.InsertLines 4, "Msgbox ""Bin da! noch etwas..."""
.InsertLines 5, "Call VBA_PW"
.InsertLines 6, "End Sub
"End With
ActiveWorkbook.VBProject.VBComponents.Import sPath
Kill sPath
Application.VBE.MainWindow.Visible = False
ActiveWorkbook.SaveAs sFile
ActiveWorkbook.Close
Application.ScreenUpdating = True
End Sub
vielen Dank im voraus,
gruß walter