# Word Mail Merge to PDF



## marka87uk (Aug 10, 2011)

Hi,

I'm trying to create individual PDF documents from a mail merge in Word.

It's choking on the PrintOut command with the error:

_Run-time error '5121':_
_Word experienced an error when trying to open the file._
_Try these suggestions._
_* Check the file permissions for the document or drive._
_* Make sure there is sufficient free memory and disk space._
_* Open the file with the Text Recovery converter._

Any ideas on how to fix? (The drive permissions are correct and there is enough file space.)


```
Sub PrintToPDF()
Dim i As Long
' i = ActiveDocument.MailMerge.DataSource.RecordCount
i = 5
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord
Do While intCounter < i
intCounter = intCounter + 1
ActivePrinter = "mmpdfprinter"
Application.PrintOut FileName:="Z:\" & _
ActiveDocument.Bookmarks("branch_number").Range.Text & " - " & _
ActiveDocument.Bookmarks("payroll_number").Range.Text & ".pdf"
ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
Loop
End Sub
```


----------



## marka87uk (Aug 10, 2011)

I assume this issue may be caused by the PDF printer driver but as I cannot change this I think it would maybe best to just loop through each record and save a copy as a Word document.

Can you point me in the right direction to do this please?


----------



## Macropod (Aug 14, 2011)

Hi Mark,

In all likelihood the error is caused by the fact that your bookmarks get deleted by the mailmerge process. Try storing the relevant mailmerge field values for each record instead, then using the stored values for the name parts.


----------



## marka87uk (Aug 15, 2011)

Thanks. I decided to leave the PDF idea due to the restrictions of the driver and chose to just save each mail merge record as it's own DOC file. I pieced together parts of a few macros and managed to get the result I wanted!

The bookmarks seem to stay throughout the mail merge process.


----------

