Mail Merge to individual PDFs

Zakkaroo

Active Member
Joined
Jul 6, 2009
Messages
383
I found the code below on this page:

http://www.mrexcel.com/forum/genera...010-mail-merge-save-individual-pdf-files.html

It appears a number of people in the thread have used it successfully, however ... in my case, absolutely nothing happens.
No errors etc. and it doesn't create any PDFs at all.
I tried changing StrName to just "test" ... to make sure that wasn't causing problems, but it still won't create a single PDF.

Just to confirm, I am trying to run the code in my main mailmerge document i.e. i have not used 'Finish & Merge' and the document contains 72 'results' / recipients.

Any help would be much appreciated.

Code:
Sub merge1record()
Application.ScreenUpdating = False
Dim StrPath As String, StrName As String, MainDoc As Document
StrPath = "C:\CENTRAL OPS\Pack\PDF Files\"
Application.ScreenUpdating = False
Set MainDoc = ActiveDocument
With MainDoc
  For i = 1 To .MailMerge.DataSource.RecordCount
    With .MailMerge
      .Destination = wdSendToNewDocument
      .SuppressBlankLines = True
      With .DataSource
        .FirstRecord = i
        .LastRecord = i
        .ActiveRecord = i
        StrName = .DataFields("Name")
      End With
      .Execute Pause:=False
    End With
    With ActiveDocument
        .ExportAsFixedFormat OutputFileName:=StrPath & StrName & ".pdf", ExportFormat:=wdExportFormatPDF, _
        OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
        Item:=wdExportDocumentContent, IncludeDocProps:=True, CreateBookmarks:=wdExportCreateNoBookmarks, _
        KeepIRM:=True, DocStructureTags:=True, BitmapMissingFonts:=True, UseISO19005_1:=False
    End With
  Next i
End With
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Re: Mail Merge to individual PDF's

I'm not sure why, but I've located the problem here:

For i = 1 To .MailMerge.DataSource.RecordCount

If I change it to:

For i = 1 To 20

then it works ... so I can get around it for now, just not sure why it doesn't work!
 
Upvote 0
Re: Mail Merge to individual PDF's

For more comprehensive code, see Send Mailmerge Output to Individual Files in the Mailmerge Tips and Tricks threads at:
Mailmerge Tips & Tricks
and:
Word Mailmerge Tips & Tricks | Windows Secrets Lounge

That said, it's not apparent why you'd be having problems with .MailMerge.DataSource.RecordCount - that's fairly standard code (as you'll see from the code in the links). What kind of data source are you using? Was the mailmerge main document connected to the data source when you ran the macro with .MailMerge.DataSource.RecordCount?
 
Upvote 0
Re: Mail Merge to individual PDF's

B__P: Directing the OP to an addin - which is far more than is needed for what's being discussed in this thread - and uses the same .MailMerge.DataSource.RecordCount logic as both his original code (from this forum) and the code I pointed to, doesn't progress anything towards a solution.
 
Upvote 0
Re: Mail Merge to individual PDF's

I had the same issue with data in a csv file and the line


For i = 1 To .MailMerge.DataSource.RecordCount

showed .MailMerge.DataSource.RecordCount to be 0 when I pushed F8 in the code.


The data file was 2600 records and 150 fields (many of them where empty).


I thought it was doing nothing but after discovering the addin I think it is something related to a kind of integrity check of the merged data and code is still working; try to wait a bit. When for the same task I used the addin it went frozen for a while (a long while) but then showed the list of recipients and the job continued perfectly.
 
Last edited:
Upvote 0
Re: Mail Merge to individual PDF's

In which case, all that might be needed is something like:
Do While .MailMerge.DataSource.RecordCount = 0
Loop
before:
For i = 1 To .MailMerge.DataSource.RecordCount
 
Upvote 0

Forum statistics

Threads
1,225,763
Messages
6,186,896
Members
453,384
Latest member
BigShanny

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