Word Mail Merge to PDF

marka87uk

Board Regular
Joined
Mar 24, 2007
Messages
247
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.)

Code:
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
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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?
 
Upvote 0
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.
 
Upvote 0
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. :)
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,733
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top