Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-25-2019, 07:32 PM
QCaesar QCaesar is offline Sending Mailmerge Output to Individual Files Windows 10 Sending Mailmerge Output to Individual Files Office 2013
Novice
Sending Mailmerge Output to Individual Files
 
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
  #2  
Old 07-25-2019, 07:44 PM
macropod's Avatar
macropod macropod is online now Sending Mailmerge Output to Individual Files Windows 7 64bit Sending Mailmerge Output to Individual Files Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,497
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

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]
Reply With Quote
  #3  
Old 07-26-2019, 06:51 AM
QCaesar QCaesar is offline Sending Mailmerge Output to Individual Files Windows 10 Sending Mailmerge Output to Individual Files Office 2013
Novice
Sending Mailmerge Output to Individual Files
 
Join Date: Jul 2019
Posts: 3
QCaesar is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Does your data source actually contain fields named "Name", "EMail" and "Student_Name" - all of which your code references?
yes it does. I changed those fields manually.
Reply With Quote
  #4  
Old 07-26-2019, 10:28 AM
QCaesar QCaesar is offline Sending Mailmerge Output to Individual Files Windows 10 Sending Mailmerge Output to Individual Files Office 2013
Novice
Sending Mailmerge Output to Individual Files
 
Join Date: Jul 2019
Posts: 3
QCaesar is on a distinguished road
Default

Actually, I figured it out. Apparently, you can't use a list that's saved in CSV format.

Thanks for the help!
Reply With Quote
  #5  
Old 07-26-2019, 03:33 PM
macropod's Avatar
macropod macropod is online now Sending Mailmerge Output to Individual Files Windows 7 64bit Sending Mailmerge Output to Individual Files Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,497
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

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]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending Mailmerge Output to Individual Files Send Mailmerge Output to Individual Files - Help with VBA plupton Mail Merge 2 12-24-2019 07:18 AM
Sending Mailmerge Output to Individual Files Mailmerge to Individual Files Creating Extra Pages cmt11 Mail Merge 2 04-21-2019 09:32 AM
Sending Mailmerge Output to Individual Files Send Mailmerge Output to Individual Files - Help Needed sunrise06 Mail Merge 4 12-22-2018 07:56 PM
Sending Mailmerge Output to Individual Files Save mailmerge records as individual word files using VBA beefcake2000 Word VBA 3 11-10-2017 09:55 PM
Sending Mailmerge Output to Individual Files Send Mailmerge Output to Individual Files - troubleshooting help mxk372 Mail Merge 1 07-06-2017 03:49 PM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 12:14 AM.


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