#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
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] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Trying to merge 2 docs | Ian76 | Word | 2 | 04-08-2019 12:58 AM |
Mail merge into separate list | mds | Mail Merge | 5 | 04-06-2016 02:17 AM |
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 |
Adding identical footers to 187 separate docs | sqzdog | Word | 11 | 10-31-2011 01:46 AM |