Reputation:
I have got an interesting question and I couldn't find an answer somewhere. I need to print around 2000 letters and of course I will do it with Mail Merge. Problem: I need every single one printed out in pdf-format. I found out that I have to use VBA macros in Word to get single letters (and not to get the whole bulk of letters in just one document) and this already works. But I couldn't find out how to automatically transfer them into pdf.
Does anyone has an idea and can help me? I appreciate your help.
What I got so far (to make single documents with mail merge):
Sub EinzelDatei()
Dim actpath As String, Dateiname As String
Dim fs As Object
Dim LetzterRec As Long
Const path As String = "D:\Test\"
On Error GoTo 0
Application.ScreenUpdating = False
Application.Visible = False
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdLastRecord
LetzterRec = Word.ActiveDocument.MailMerge.DataSource.ActiveRecord
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord
With ActiveDocument.MailMerge
.DataSource.ActiveRecord = wdFirstRecord
Do
If .DataSource.ActiveRecord > 0 Then
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
actpath = path & "\" 'Der aktuelle Pfad wird zusammengesetzt
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.folderexists(actpath) = False Then MkDir (actpath) 'Wenn der Pfad noch nicht existiert wird er jetzt erstellt
.FirstRecord = .ActiveRecord
.LastRecord = .ActiveRecord
Dateiname = actpath & _
.DataFields("No").Value & "-" & _
.DataFields("Surname").Value & "," & _
.DataFields("First_Name").Value & ".docx" 'Dateiname = Name, Vorname.doc
End With
.Execute Pause:=False
ActiveDocument.SaveAs FileName:=Dateiname '
ActiveDocument.Close False
End If
If .DataSource.ActiveRecord < LetzterRec Then
.DataSource.ActiveRecord = wdNextRecord
Else
Exit Do
End If
Loop
End With
MsgBox ("Erledigt")
Application.Visible = True
Application.ScreenUpdating = True
End Sub
Thank you in advance!!!
Upvotes: 0
Views: 2244
Reputation: 34232
In Word 2007 it's the export functionality that can save a file as pdf:
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
"Path to PDF", ExportFormat:= _
wdExportFormatPDF
Upvotes: 1
Reputation: 1
Bit simple, but you can just set your default printer to PDF creator then use the print function.In 2010 you get a print or edit option once you've done the merge.
Upvotes: 0
Reputation:
Use
ActiveDocument.SaveAs FileName:=Dateiname, FileFormat:=wdsaveformat.wdFormatPDF
or maybe
ActiveDocument.SaveAs2 FileName:=Dateiname, FileFormat:=wdsaveformat.wdFormatPDF
But it can only work in Word 2007 SP2 (I think) and later.
Upvotes: 1