ich möchte gerne folgende Funktionalität programmieren:
In Excel habe ich ein Arbeitsblatt mit jeder Menge Word Dateien.
Ich möchte nun in ein erstelltes Worddokument "Vorlage.docx" verschiedene weitere Dokumente "Baustein.docx" inklusive Formatierung übernehmen.
Anbei das Makro wie ich es zum probieren erstellt habe.
(copy/paste über Zwischenablage)
Leider wird der Inhalt aus der Zwischenablage nicht am Ende des Dokuments eingefügt, sondern überschreibt alles.
Danke schon im Vorhinein für jede Hilfe
P.S. Die Word Bibliothek habe ich eingebunden
Sub Copy_Baustein()
Dim wrdApp As Word.Application
Dim Vorlage, Baustein As Word.Document
Dim i As Integer
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set Baustein = wrdApp.Documents.Open("C:\TEMP\Baustein.docx")
With Baustein
.Content.Select
.Content.Copy
End With
Set Vorlage = wrdApp.Documents.Open("C:\TEMP\Vorlage.doc")
With Vorlage
.Activate
.Content.Collapse Direction:=wdCollapseEnd ' Das funktioniert anscheinend nicht
.Content.Paste
If Dir("C:\TEMP\neu.doc") "" Then
Kill "C:\TEMP\neu.doc"
End If
.SaveAs ("C:\TEMP\neu.doc")
.Close ' close the document
End With
wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub