AW: Excell tabelle in word Übertragen
08.06.2015 14:09:07
fcs
Hallo Alex,
VBA-Alternative zu dem von Jochen vorgeschlagenen Serienbrief.
Allerdings funktioniert die Übertragung nach Word einfacher, wenn das Formblatt als Tabelle aufgebaut ist und das Firmenloge in die Kopfzeile eingfügt wird. Mit den Wordformen wird das Übertragen wesentlich komplizierter, da Seitenumbrüche eingefügt und die Textformen entsprechend plaziert/formatiert werden müssen.
Hier die Worddatei entsprechend modifiziert (als Zip-Datei).
https://www.herber.de/bbs/user/98078.zip
Nachfolgend das Excel-Makro zur Übertragung der Daten in die Wordvorlage
Gruß
Franz
'Makro in einem allgemeinen VBA-Modul in Excel
Sub Export_Data_to_Wordfile()
Dim xlWks As Worksheet
Dim xlZeile As Long, xlZeile_L As Long
Dim wdApp As Object 'Word.Application
Dim wdDoc As Object 'Word.Document
Dim wdTab As Object 'Word.Table
Dim wdZeile As Long
Dim strDot As String
Set xlWks = ActiveSheet
'Word-Dokumentvorlage
strDot = "D:\Test\Trennblaetter.dot" 'Verzeichnis anpassen!!
Set wdApp = VBA.CreateObject("Word.Application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Add(Template:=strDot)
Set wdTab = wdDoc.Tables(1)
With xlWks
xlZeile_L = .Cells(.Rows.Count, 2).End(xlUp).Row
With wdTab
For xlZeile = 2 To xlZeile_L
If xlZeile > 2 Then
.Rows.Add
End If
wdZeile = .Rows.Count
.Cell(wdZeile, 2).Range.Text = xlWks.Cells(xlZeile, 3).Text
.Cell(wdZeile, 3).Range.Text = xlWks.Cells(xlZeile, 2).Text
Next
End With
End With
ActiveWorkbook.Activate
MsgBox "Fertig!", vbInformation, "Übertragung in Word-Vorlage"
End Sub