#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
Does your data source actually contain fields named "Name", "EMail" and "Student_Name" - all of which your code references?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
yes it does. I changed those fields manually.
|
#4
|
|||
|
|||
Actually, I figured it out. Apparently, you can't use a list that's saved in CSV format.
Thanks for the help! |
#5
|
||||
|
||||
The file format of the data source is of no consequence. Perhaps there were other issues with your CSV file.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Send Mailmerge Output to Individual Files - Help with VBA | plupton | Mail Merge | 2 | 12-24-2019 07:18 AM |
Mailmerge to Individual Files Creating Extra Pages | cmt11 | Mail Merge | 2 | 04-21-2019 09:32 AM |
Send Mailmerge Output to Individual Files - Help Needed | sunrise06 | Mail Merge | 4 | 12-22-2018 07:56 PM |
Save mailmerge records as individual word files using VBA | beefcake2000 | Word VBA | 3 | 11-10-2017 09:55 PM |
Send Mailmerge Output to Individual Files - troubleshooting help | mxk372 | Mail Merge | 1 | 07-06-2017 03:49 PM |