Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-03-2019, 12:38 PM
sdemuth@earthlink.net sdemuth@earthlink.net is offline Save each individual merged document as its own file Windows 10 Save each individual merged document as its own file Office 2016
Novice
Save each individual merged document as its own file
 
Join Date: Oct 2019
Posts: 4
sdemuth@earthlink.net is on a distinguished road
Default Save each individual merged document as its own file

I need to save each individual merged document as its own file.



I have searched on the internet and found nothing that seems to work for me. I cannot download and install an add-in because they do not allow us to do that at work.

Does anyone have VBA code that I can run after the merge that will accomplish this task?

Any help will be greatly appreciated!

juniormint
Reply With Quote
  #2  
Old 10-03-2019, 03:42 PM
macropod's Avatar
macropod macropod is offline Save each individual merged document as its own file Windows 7 64bit Save each individual merged document as its own file Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Did you look in the Mailmerge Tips and Tricks 'Sticky' thread at the top of this forum: Mailmerge Tips & Tricks
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 10-03-2019, 04:55 PM
sdemuth@earthlink.net sdemuth@earthlink.net is offline Save each individual merged document as its own file Windows 10 Save each individual merged document as its own file Office 2016
Novice
Save each individual merged document as its own file
 
Join Date: Oct 2019
Posts: 4
sdemuth@earthlink.net is on a distinguished road
Default

Thank you for your response!

Yes - I tried the code under the heading Send Mailmerge Output to Individual Files, but when I ran the code, nothing happened. Any idea what may be causing that?
Reply With Quote
  #4  
Old 10-03-2019, 07:15 PM
macropod's Avatar
macropod macropod is offline Save each individual merged document as its own file Windows 7 64bit Save each individual merged document as its own file Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

There's any number of possibilities, including:
1. You're not running the code from a mailmerge main document; and/or
2. You haven't edited the 'Last_Name' & 'First_Name' references in the code to reflect your own field names.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 10-04-2019, 09:37 AM
sdemuth@earthlink.net sdemuth@earthlink.net is offline Save each individual merged document as its own file Windows 10 Save each individual merged document as its own file Office 2016
Novice
Save each individual merged document as its own file
 
Join Date: Oct 2019
Posts: 4
sdemuth@earthlink.net is on a distinguished road
Default Separate mail merge into individual documents

Hi Paul -

Thanks for replying. I have the following code from the internet. Can you check it to see if there is something wrong with the changes I made to it?

Also, I put it under the VBA code where it says (General) on the left-hand side at the top and the right-hand drop down is Merge_To_Individual_Files. Is that right?

I tried running it by pressing F5 and it just sits there.

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("Report_Name")) = "" Then Exit For
        'StrFolder = .DataFields("Folder") & Application.PathSeparator

        StrName = .DataFields("Report_Name")
            '& "_" & .DataFields("First_Name")
      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
      'Add the name to the footer
      '.Sections(1).Footers(wdHeaderFooterPrimary).Range.InsertBefore StrName
      .SaveAs FileName:=StrFolder & StrName & ".docx", FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False

      ' and/or:
      '.SaveAs FileName:=StrFolder & StrName & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False
      '.Close SaveChanges:=False
    End With
NextRecord:
  Next i
End With

Application.ScreenUpdating = True
End Sub
Any help will be appreciated!
Reply With Quote
  #6  
Old 10-04-2019, 09:37 PM
macropod's Avatar
macropod macropod is offline Save each individual merged document as its own file Windows 7 64bit Save each individual merged document as its own file Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Your code refers to a field named 'Report_Name'. Does your data source have such a field? Is any of the records for that field empty? If so the code will exit at the first empty record.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 10-07-2019, 05:28 AM
sdemuth@earthlink.net sdemuth@earthlink.net is offline Save each individual merged document as its own file Windows 10 Save each individual merged document as its own file Office 2016
Novice
Save each individual merged document as its own file
 
Join Date: Oct 2019
Posts: 4
sdemuth@earthlink.net is on a distinguished road
Default Mail Merge - save each individual merged document as its own file

Thanks for responding! My main merge document does have a field called "Report_Name," as does the Excel document to be merged with.

I should point out that "Report_Name" occurs as the title of each document, plus a field in the document body with "Report_Name"; in other words, two times in each report.

Also, the "Report_Name" that occurs in the body itself is within a table. There are two tables in each report.

Would any of the two points mentioned above have anything to do with the problem?

Thanks again!

juniormint
Reply With Quote
  #8  
Old 10-07-2019, 11:21 PM
macropod's Avatar
macropod macropod is offline Save each individual merged document as its own file Windows 7 64bit Save each individual merged document as its own file Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by sdemuth@earthlink.net View Post
Thanks for responding! My main merge document does have a field called "Report_Name," as does the Excel document to be merged with.
Are you sure the field in the data source is named 'Report_Name' and not 'Report Name'? The mergefield name isn't relevant here, as mergefields substitute underscores for spaces.

The number of times the field appears in the mailmerge main document is of no consequence.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Save each individual merged document as its own file Splitting merged Word document into individual .pdf documents (naming from a field in the file) ScarlettNZ Mail Merge 1 05-30-2019 12:53 AM
Save each individual merged document as its own file Word crashes if the merged document file is closed first reidtaylor Mail Merge 7 05-07-2019 04:19 AM
Save a section as individual document. eduzs Word VBA 1 10-29-2018 07:35 AM
Save each individual merged document as its own file How can I save a Word Document as a PDF file with a merged field filename? kp2009 Word VBA 5 08-27-2015 11:45 PM
Save merged document as concatenated merge field values texas791 Word VBA 4 02-25-2014 07:35 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:18 AM.


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