Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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
 



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 02:58 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