View Single Post
 
Old 07-25-2019, 07:32 PM
QCaesar QCaesar is offline Windows 10 Office 2013
Novice
 
Join Date: Jul 2019
Posts: 3
QCaesar is on a distinguished road
Question Sending Mailmerge Output to Individual Files

I am trying to use this macro to save the output files to pdf however it is not working. I am not receiving any error message or anything. Just nothing. Here is the formula.

Code:
Sub Merge_To_Individual_Files()
' Sourced from: https://www.msofficeforums.com/mail-...ps-tricks.html
Application.ScreenUpdating = False
Dim StrFolder As String, StrName As String, MainDoc As Document, i As Long, j As Long
Const StrNoChr As String = """*./\:?|"
Set MainDoc = ActiveDocument
With MainDoc
  StrFolder = .Path & Application.PathSeparator
  For i = 1 To .MailMerge.DataSource.RecordCount
    With .MailMerge
      .Destination = wdSendToNewDocument
      .SuppressBlankLines = True
      With .DataSource
        .FirstRecord = i
        .LastRecord = i
        .ActiveRecord = i
        If Trim(.DataFields("Name")) = "" Then Exit For
        'StrFolder = .DataFields("Folder") & Application.PathSeparator
        StrName = .DataFields("EMail") & "-STUDENT NAME-" & .DataFields("Student_Name") & "-SHAQ-TO-SCHOOL TICKET"
      End With
      .Execute Pause:=False
      If Err.Number = 5631 Then
        Err.Clear
        GoTo NextRecord
      End If
    End With
      For j = 1 To Len(StrNoChr)
        StrName = Replace(StrName, Mid(StrNoChr, j, 1), "_")
      Next
    StrName = Trim(StrName)
    With ActiveDocument
      .SaveAs FileName:=StrFolder & StrName & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False
      .Close SaveChanges:=False
    End With
NextRecord:
  Next i
End With
Application.ScreenUpdating = True
End Sub

Last edited by macropod; 07-25-2019 at 07:38 PM. Reason: Added code tags
Reply With Quote