PDA

View Full Version : WORD MAILMERGE EXTRACT TO INDIVIDUAL PDF FILES



stevembe
09-13-2016, 05:31 AM
Thank you in advance for reading. I have a word mail merge document but I want which has a section break at the end of each document but what I am looking for some VBA that when run will:

Split the mail merge
Save to a specified folder but as a pdf file

I have found some code on the internet but I am unable to get any of it to work.

stevembe
09-13-2016, 05:34 AM
I meant to add I found the following code but it just prompts me to define a file path and then nothing more, not even a Runtime Error:


Public Sub CreatePDF()
'
' CreatePDF Macro
'
'
' From: Word 2007/2010 Mail Merge to save to individual PDF files (http://www.mrexcel.com/forum/general-excel-discussion-other-questions/713478-word-2007-2010-mail-merge-save-individual-pdf-files.html)

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

ThisDoc = ActiveDocument.Name
ChangeFileOpenDirectory SelectedPath
For i = 1 To ActiveDocument.MailMerge.DataSource.RecordCount
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
' MsgBox "Press OK"
With .DataSource
.FirstRecord = i
.LastRecord = i
.ActiveRecord = i
docname = .DataFields("Batch").Value & ".pdf"
End With
.Execute Pause:=False
Application.ScreenUpdating = True


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 False
' Windows(ThisDoc).Activate
Next i
Application.ScreenUpdating = True
End Sub

gmayor
09-13-2016, 09:26 PM
See http://www.gmayor.com/individual_merge_letters.htm

stevembe
09-13-2016, 11:15 PM
See http://www.gmayor.com/individual_merge_letters.htm

Thanks but add ins are not permitted, work pc.

gmayor
09-14-2016, 06:14 AM
But they will allow you to use macros, without the knowledge and experience to utilise them properly, that can potentially cause a lot of damage to company filing systems? Astonishing.