Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-28-2022, 10:13 PM
chrnon chrnon is offline Merge into Separate Docs Windows 10 Merge into Separate Docs Office 2013
Novice
Merge into Separate Docs
 
Join Date: Feb 2022
Posts: 1
chrnon is on a distinguished road
Default Merge into Separate Docs

Hello,
I have been trying to use the macro listed in "tips and tricks" to merge into individual documents. It has worked for me in the past but this time, it will not work.
I have renamed "MailMergeToDoc". When I go back to the main document, finish and merge, edit individual documents.... it doesn't do anything. I am not sure what I am doing wrong or why it will not initiate.
If anyone can help me out, I would really appreciate!



My code:

Code:
Sub MailMergeToDoc()
' 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 & "\"
  With .MailMerge
    .Destination = wdSendToNewDocument
    .SuppressBlankLines = True
    On Error Resume Next
    For i = 1 To .DataSource.RecordCount
      With .DataSource
        .FirstRecord = i
        .LastRecord = i
        .ActiveRecord = i
        If Trim(.DataFields("Last_Name")) = "" Then Exit For
        'StrFolder = .DataFields("Folder") & "\"
        StrName = .DataFields("Folder_Name") & "_" & .DataFields("Last_Name")
      End With
      On Error GoTo NextRecord
      .Execute Pause:=False
      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
End With
Application.ScreenUpdating = True
End Sub
Reply With Quote
  #2  
Old 04-27-2022, 03:08 PM
macropod's Avatar
macropod macropod is offline Merge into Separate Docs Windows 10 Merge into Separate Docs Office 2016
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 chrnon View Post
I have renamed "MailMergeToDoc". When I go back to the main document, finish and merge, edit individual documents.... it doesn't do anything. I am not sure what I am doing wrong or why it will not initiate.
In the code you posted, the macro is still named "MailMergeToDoc". Most likely your renaming (or not) is the issue.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to merge 2 docs Ian76 Word 2 04-08-2019 12:58 AM
Merge into Separate Docs Mail merge into separate list mds Mail Merge 5 04-06-2016 02:17 AM
Merge into Separate Docs Merge info into 5 separate documents kenjmaraty Word 3 07-06-2015 07:30 AM
Link cells in word doc (table) to update from 2 separate docs - can this be done? larrens Word 3 09-15-2014 11:20 PM
Merge into Separate Docs Adding identical footers to 187 separate docs sqzdog Word 11 10-31-2011 01:46 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:20 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