Microsoft Word – Mail Merge Separate Documents and Save File Name as Mail Merge Variable

Setup your Microsoft Word mail merge by selecting your data source and the recipients. Don’t actually complete the mail merge.

Create two Macro’s, one called “StartMailMerge” and the other called “DoWork”.

 

StartMailMerge – Code

Sub Start()

For i = 1 To ActiveDocument.MailMerge.DataSource.RecordCount

    DoWork

Next i

End Sub

DoWork – Code

Sub DoWork()

    Dim DokName  As String

 

    With ActiveDocument.MailMerge

        .Destination = wdSendToNewDocument

        .SuppressBlankLines = True

        With .DataSource

            .FirstRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord

            .LastRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord

            DokName = .DataFields("FieldName").Value      'Change "FieldName" to your MailMerge field name

        End With

 

' Merge the active record

        .Execute Pause:=False

    End With

 

' Save the resulting document.

    ActiveDocument.SaveAs2 FileName:="C:\temp\"+ DokName + ".docx", FileFormat:= _

        wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _

        :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _

        :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _

        SaveAsAOCELetter:=False, CompatibilityMode:=14

 

' Close the resulting document

    ActiveWindow.Close

 

' Now, back in the template document, advance to next record

    ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord

End Sub

When you’re finished, just run the StartMailMerge macro.

Leave a Comment

Your email address will not be published. Required fields are marked *