Hi There
This is my first post on the forum, so apologies if the format isn't quite right. I modified the "Send Mailmerge Output to Individual Files" code kindly posted
here so suit my needs. I was able to complete my task, but had a few annoying niggles.
- The screen kept updating. I had intended to stop this but new Word windows kept opening with each individual file.
I experienced what appears to be the same error described here. This is why I commented out the ".Close SaveChanges:=False" line in the code - otherwise Word would crash. This meant it worked, but due to the large number of files being open my PC slowed down significantly.The user in the thread I linked to said they resolved the issue by making the document not a template. This is probably my lack of knowledge, but I didn't understand what was meant by this - could someone assist? To the best of my knowledge I haven't made the document a template.
Thanks so much for your help! I've pasted my code below.
Code:
Sub AutoMerge()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim StrFolder As String, StrName As String, MainDoc As Document, i As Long, j As Long
Set MainDoc = ActiveDocument
StrFolder = Path & "\"
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
For i = 1 To 10
With .DataSource
.FirstRecord = i
.LastRecord = i
.ActiveRecord = i
StrName = "C:\Users\X\Documents\" & .DataFields("Name")
End With
If ShouldWeSave = 1 Then
.Execute Pause:=False
Application.ScreenUpdating = False
ActiveDocument.SaveAs2 FileName:=StrName & ".docx", FileFormat:=wdFormatXMLDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=False, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False, CompatibilityMode:=15
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
StrName & ".pdf" _
, ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
'.Close SaveChanges:=False
End If
NextRecord:
Next i
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub