Try:
Naturally, you'll need to use your own path for the StrPath variable and, if you're not saving docx files, change the '.SaveAs2' line to:Code:Sub merge1record_at_a_time() Application.ScreenUpdating = False Dim StrPath As String, StrName As String, MainDoc As Document StrPath = "C:\File path\" Application.ScreenUpdating = False Set MainDoc = ActiveDocument With MainDoc For i = 1 To .MailMerge.DataSource.RecordCount With .MailMerge .Destination = wdSendToNewDocument .SuppressBlankLines = True With .DataSource .FirstRecord = i .LastRecord = i .ActiveRecord = i StrName = .DataFields("ID") End With .Execute Pause:=False End With With ActiveDocument .SaveAs2 FileName:=StrPath & StrName & ".docx", FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False .Close SaveChanges:=False End With Next i End With Application.ScreenUpdating = True End Sub
Code:.ExportAsFixedFormat OutputFileName:=StrPath & StrName & ".pdf", ExportFormat:=wdExportFormatPDF, _ OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _ Item:=wdExportDocumentContent, IncludeDocProps:=True, CreateBookmarks:=wdExportCreateNoBookmarks, _ KeepIRM:=True, DocStructureTags:=True, BitmapMissingFonts:=True, UseISO19005_1:=False
Dear Macropad,
I used the above code to generate .pdf file and it is working perfectly well. For my testing I created 10 .pdf files and it worked as expected. But this has also created 37 word document I do not know how but I need to delete each word file one by one and it is not even allowing me to close the word application. Then from Task manager I had to select all word files and kill the process. Will you please help me the word document created should get closed without intervention and my .pdf files alone should be in the folder.
Regards,
Prakash