Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Macro for Microsoft Word (written in Visual Basic) that will save or print each entry in a mail merge. It was created to be used when printing a newsletter that required printing, folding, and stapling. Unless each entry for the mail merge was printed separately, the printer tried to fold and staple several newsletters at once.
Sub PrintMailMergeSeparately()
'
' PringMailMergeSeparately Macro
' - This macro prints each mail merge as an individual document to aid in folding and stapling
'
Dim lname As String
Dim totalMailings As Long
Dim i As Integer
totalMailings = ActiveDocument.MailMerge.DataSource.RecordCount
ActiveDocument.MailMerge.DataSource.ActiveRecord = 1 ' Start the mailmerge at the beginning
For i = 1 To totalMailings Step 1
lname = ActiveDocument.MailMerge.DataSource.DataFields(2).Value
FName = ActiveDocument.MailMerge.DataSource.DataFields(3).Value
FullName = FName + " " + lname
' uncomment the next line to save the entries - Be sure to enter the filename you want
' ActiveDocument.SaveAs2 FileName:="{enter your filename here} - " + FullName + ".docx", FileFormat:= _
wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False, CompatibilityMode:=14
ActiveDocument.PrintOut
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
Next i
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment