ich arbeite an einem Datenexport von Excel zu Word. Dafür habe ich ein Makro geschrieben, indem ein bestimmter Tabellenbereich in Excel kopiert und in eine Word Dokument Vorlage an einer vorher gesetzten Bookmark eingefügt wird. Klappt soweit auch, nur schaffe ich es nicht die Tabellenposition mit VBA von linksbündig auf zentriert zu setzen. In Word händisch natürlich ja eigentlich kein Problem. Die Tabelle wird im Dokument zwar als Table erkannt (Debug.Print ActiveDocument.Tables.count reagiert korrekt.) Der Nachfolgende Befehl zur Zentrierung läuft aber ins Leere.
Hat jemand eine Idee an was das liegen könnte?
LG FX
Dim wdApp As Word.Application, wdDoc As Word.Document, wdTbl As Word.Table
Dim path, testname, DefaultName As String
Set wdApp = New Word.Application
wdApp.Documents.Add "file:///\\C:\TEMPLATE.docx"
wdApp.Visible = True 'Sichtbar
wdApp.Activate 'Sichtbar
testname = Worksheets("Overview").Range("C13").Value & " " & Range("B1").Value & " " & Range("D1").Value
wdApp.selection.GoTo what:=-1, Name:="Testname"
wdApp.selection.InsertAfter testname
wdApp.selection.EndKey Unit:=wdLine
wdApp.selection.TypeParagraph
wdApp.selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
ThisWorkbook.Worksheets(StName).Range("A2", "G19").Copy
wdApp.selection.PasteAndFormat Type:=wdFormatOriginalFormatting
ThisWorkbook.Worksheets(StName).Application.CutCopyMode = False
' ------ Zentrierung der Tabelle
wdApp.Activate
Debug.Print wdApp.ActiveDocument
Debug.Print ActiveDocument.Tables.count
Dim tbl As Table
For Each tbl In ActiveDocument.Tables
tbl.Rows.Alignment = wdAlignRowCenter
Next tbl