Dim
Word
As
Object
Dim
strDatenQuelle
As
String
Dim
WinDoc
As
Object
Const
WD_STORY = 6
Dim
strEnv
As
String
strPfad = "C:\Users\test\"
Set
Word = CreateObject(
"Word.Application"
)
strDatenQuelle =
"C:\Users\test\Export.xlsx"
Word.Visible =
True
With
Word
Set
WinDoc = Word.documents.Open(
"C:\Users\test\neu.docx"
)
With
WinDoc
With
.MailMerge
.OpenDataSource Name:=strDatenQuelle, LinkToSource:=
True
, Format:=0, SQLStatement:=
"SELECT * FROM `Tabelle1$`"
.Destination = 0
.SuppressBlankLines =
True
With
.DataSource
End
With
.Execute Pause:=
False
End
With
End
With
Set
docSerienbrief = .documents(1)
.documents(1).Activate
WinDoc.Close
False
.Selection.WholeStory
.Selection.Fields.Update
.Selection.HomeKey Unit:=WD_STORY
.documents(1).SaveAs2 Filename:=strPfad &
"Anschreiben.pdf"
, FileFormat:=wdFormatPDF
.documents(1).Close SaveChanges =
False
End
With
End
Sub