How would I create individuals files from mail merge rather than the one large file that is output by the mail merge function in Microsoft Office? I was hoping to be able to save each letter than was created as a name of one of the merge fields, but I haven't been able to find an intuitive way so far.
1.1m 316 316 gold badges 4.2k 4.2k silver badges 3.4k 3.4k bronze badges asked Nov 5, 2014 at 13:37 116 1 1 gold badge 1 1 silver badge 10 10 bronze badgesI added the VBA tag to the question, but note that if you wanted to do this without Word (eg using C#), you could do so using docx4j.NET
Commented Nov 17, 2014 at 23:18See Send Mailmerge Output to Individual Files in the Mailmerge Tips and Tricks thread at msofficeforums.com/mail-merge/21803-mailmerge-tips-tricks.html or windowssecrets.com/forums/showthread.php/…
Commented Jan 14, 2019 at 20:55Recently I've come across the similar situation where I want to save individual files in pdf format rather than saving one large file created by Mail merge function. I've written down this small function to save individual file in pdf format.
Sub SaveAsPDF() Dim CouncilName As String With ActiveDocument.MailMerge .Destination = wdSendToNewDocument .SuppressBlankLines = True For SectionCount = 1 To .DataSource.RecordCount With .DataSource 'FirstRecord and LastRecords defines how many data records needs to be merge in one document. 'createing pdf file for each data record so in this case they are both pointing to ActiveRecord. .FirstRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord .LastRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord 'get the council name from data source CouncilName = .DataFields("Council").Value 'move to next datasource record. If .ActiveRecord <> .RecordCount Then .ActiveRecord = wdNextRecord End If End With 'Get path and file name PDFPathAndName = ActiveDocument.Path & Application.PathSeparator & "FINAL - " & CouncilName & ".pdf" ' Merge the document .Execute Pause:=False ' Save resulting document. Set PDFFile = ActiveDocument PDFFile.ExportAsFixedFormat PDFPathAndName, wdExportFormatPDF PDFFile.Close 0 Next End With End Sub
answered Nov 17, 2014 at 6:45
Parth Parmar Parth Parmar
31 1 1 bronze badge
I will try this, but would it preserve security features i.e. editable fields in the document?
Commented Nov 18, 2014 at 13:18
as of my experience, there is no option to save individual files, instead you can use Macro to spit the files and save it individually with specific name that you want. I have tried the same and succeeded with what want. Hope the below code helps you as well to achieve you goal.
Sub BreakOnSection() 'Used to set criteria for moving through the document by section. Application.Browser.Target = wdBrowseSection 'A mailmerge document ends with a section break next page. 'Subtracting one from the section count stop error message. For i = 1 To ((ActiveDocument.Sections.Count) - 1) 'Select and copy the section text to the clipboard ActiveDocument.Bookmarks("\Section").Range.Copy 'Create a new document to paste text from clipboard. Documents.Add 'To save your document with the original formatting' Selection.PasteAndFormat (wdFormatOriginalFormatting) 'Removes the break that is copied at the end of the section, if any. Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend Selection.Delete Unit:=wdCharacter, Count:=1 ChangeFileOpenDirectory "C:\" DocNum = DocNum + 1 ActiveDocument.SaveAs FileName:="test_" & DocNum & ".doc" ActiveDocument.Close 'Move the selection to the next section in the document Application.Browser.Next Next i ActiveDocument.Close savechanges:=wdDoNotSaveChanges End Sub
Please revert me for any clarifications.