Word 2007/2010 Mail Merge to save to individual PDF files

kryptonian

Board Regular
Joined
Oct 6, 2006
Messages
104
I tried using gmayor's Individual Merge Letters solution but my file only closes without doing anything so I am posting here as a last recourse...

Here's what I want to do --

I'm using Word 2007/2010 mail merge and I want to create individual PDF files. Currently, we do it the long way, saving it one PDF at a time using Save As. This works if it only a handful of letters but it becomes a pain when we're processing hundreds! Data source is an Excel file.

Any help would be greatly appreciated!
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi guys I'm new to the forum but I've been using the tips here for around 2 years now. I'm wondering if anyone knows why i get the error "Directory name is not valid"? It seems no matter what version I use, it throws the same runtime error.
 
Upvote 0
Without knowing which 'version' you're using or how your system's folder structure compares with the code you're using, no one tell you what specific changes to make. Evidently, though, the folder your code specifies doesn't exist.
 
Upvote 0
Hi Macropod, I managed to solve this late last night. Turns out the datafield I was pulling the value from contained a special character, as it worked when I used Date() as the filename. Maybe this will help somebody with the same issue, as the error was way of its target :)
 
Upvote 0
Hi All,

I've been using this macro for the last three years and thanks again to the people who contributed. I have a small problem though, the macro gets slower and slower over time. It runs at one pdf file per second for around an hour and then gradually starts slowing down, until it's almost one file per seven seconds. This significantly slows down the entire exercise as my files run into tens of thousands. This could have nothing to do with the macro itself, but I would be grateful if someone tells me a workaround...thanks.

If someone knows of a tool that can do the same function of creating pdf files from spreadsheets (along with images from image paths in the spreadsheet), please let me know. I can pay for it...
 
Upvote 0
I've been using this macro for the last three years and thanks again to the people who contributed. I have a small problem though, the macro gets slower and slower over time.
Which of the many different macros in this thread do you mean? Have you tried the later iterations - especially the macro in either of the links I supplied in post #81?
 
Upvote 0
Oops, sorry. The code I'm using is as below. It works perfectly, apart from the slowing down part.
----------------------------------------------------------
Code:
Sub merge1record_at_a_time() '
' merge1record_at_a_time Macro
'
'
    Dim fd As FileDialog
    'Create a FileDialog object as a Folder Picker dialog box.
    Set fd = Application.FileDialog(msoFileDialogFolderPicker)
    With fd
        'Use the Show method to display the Folder Picker dialog box and return the user's action.
        'The user pressed the button.
        If .Show = -1 Then
                For Each vrtSelectedItem In .SelectedItems
                'vrtSelectedItem is aString that contains the path of each selected item.
                'You can use any file I/O functions that you want to work with this path.
                'This example displays the path in a message box.
        SelectedPath = vrtSelectedItem

        Next vrtSelectedItem
Else
        MsgBox ("No Directory Selected.  Exiting")
        Exit Sub
        End If
    End With
'Set the object variable to Nothing.
    Set fd = Nothing
Application.ScreenUpdating = False

MainDoc = ActiveDocument.Name
    ChangeFileOpenDirectory SelectedPath
    For i = 1 To ActiveDocument.MailMerge.DataSource.RecordCount
        With ActiveDocument.MailMerge
            .Destination = wdSendToNewDocument
            .SuppressBlankLines = True
            With .DataSource
                .FirstRecord = i
                .LastRecord = i
                .ActiveRecord = i
                docName = .DataFields("Candidate_Regn_ID").Value & ".PDF"      ' ADDED CODE
            End With
            .Execute Pause:=False
    Application.ScreenUpdating = False
            
        End With
    ActiveDocument.ExportAsFixedFormat OutputFileName:=docName, _
        ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
        wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, to:=1, _
        Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
        CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
        BitmapMissingFonts:=True, UseISO19005_1:=False
ActiveWindow.Close SaveChanges:=False
Next i
Application.ScreenUpdating = True
End Sub
 
Last edited by a moderator:
Upvote 0
Although the code in the links I provided in post #81 is more efficient, the most likely reason for the significant slowdown with so many records is that Word isn't being given any time for its housekeeping. To that end, you could replace your redundant second instance of:
Application.ScreenUpdating = False
with:
If i Mod 100 = 0 Then DoEvents

You might also replace:
Code:
    ActiveDocument.ExportAsFixedFormat OutputFileName:=docName, _
        ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
        wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, to:=1, _
        Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
        CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
        BitmapMissingFonts:=True, UseISO19005_1:=False
ActiveWindow.Close SaveChanges:=False
with:
Code:
    With ActiveDocument
      .SaveAs FileName:=docName & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False
      .Close SaveChanges:=False
    End With
 
Upvote 0
I missed that you're already adding ".pdf" to docName. Try changing:
.SaveAs FileName:=docName & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False
to:
.SaveAs FileName:=SelectedPath & "" & docName, FileFormat:=wdFormatPDF, AddToRecentFiles:=False
and deleting:
ChangeFileOpenDirectory SelectedPath
 
Upvote 0

Forum statistics

Threads
1,223,391
Messages
6,171,820
Members
452,426
Latest member
cmachael

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