Sub
SavePrintAsPDFAndDoc2()
Dim
i
As
Integer
Dim
drucken
As
Boolean
Dim
Path
As
String
Dim
sBrief
As
String
Dim
iRst
As
Integer
Dim
doc
As
Document
drucken =
True
Path = "L:\temp\Serienbriefe\Ausgabe\"
For
i = 1
To
5
With
ActiveDocument.MailMerge
.DataSource.ActiveRecord = wdFirstRecord
For
iRst = 1
To
.DataSource.RecordCount
.DataSource.ActiveRecord = iRst
.Destination = wdSendToNewDocument
.SuppressBlankLines =
True
With
.DataSource
.FirstRecord = .ActiveRecord
.LastRecord = .ActiveRecord
sBrief = Path & .DataFields(
"VBA"
).Value
End
With
If
i = 1
Then
.Execute Pause:=
False
ActiveDocument.SaveAs2 FileName:=sBrief &
".docx"
VBA.DoEvents
If
drucken =
True
Then
ActiveDocument.PrintOut
End
If
ActiveDocument.ExportAsFixedFormat OutputFileName:=sBrief &
".pdf"
, ExportFormat:=wdExportFormatPDF, OpenAfterExport:=
False
, OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument
VBA.DoEvents
ActiveDocument.Close
False
Else
If
drucken =
True
Then
Set
doc = Application.Documents.Open(FileName:=sBrief &
".docx"
)
doc.PrintOut
Debug.Print sBrief
doc.Close
False
End
If
End
If
Next
End
With
Next
End
Sub