Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 12-01-2021, 10:24 PM
gmayor's Avatar
gmayor gmayor is offline Automate mail merge to save each record individually using VBA Windows 10 Automate mail merge to save each record individually using VBA Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following will work, however may I suggest you look at the merge to documents mode of E-Mail Merge Add-in

Code:
Option Explicit

Sub SaveIndividualWordFiles()
Dim i As Long
Dim docMail As Document
Dim docLetters As Document
Dim savePath As String, sFName As String

    Set docMail = ActiveDocument
    savePath = docMail.path & "\"

    With docMail.MailMerge
        For i = 1 To .DataSource.RecordCount
            .Destination = wdSendToNewDocument
            .SuppressBlankLines = True
            With .DataSource
                .FirstRecord = i
                .LastRecord = i
                .ActiveRecord = i
                '' This will be the file name
                '' the test data source had unique surnames
                '' in a field (column) called FileName
                sFName = .DataFields("Title").value
            End With
            .Execute Pause:=False
            Set docLetters = ActiveDocument

            ' Save generated document and close it after saving
             docLetters.SaveAs FileName:=savePath & sFName & ".docx"
            docLetters.Close False
            DoEvents
        Next
    End With
Set docMail = Nothing
Set docLetters = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 

Tags
mail merge, mail merge code, mail merge saving

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automate mail merge to save each record individually using VBA How to mail merge next record on same page to save paper klc9761 Mail Merge 1 04-22-2017 02:29 PM
Automate mail merge to save each record individually using VBA Showing record number during mail merge catflap Mail Merge 1 04-13-2017 07:32 AM
Automate mail merge to save each record individually using VBA Mail Merge Next Record If rule RHensley Mail Merge 10 03-07-2017 08:05 AM
Automate mail merge to save each record individually using VBA Automate daily mail merge JCInfo Mail Merge 4 12-02-2013 05:12 PM
avoid duplicete record and merge the record with the existed record hemant.behere Excel 0 01-10-2012 02:53 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:59 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft