THIS WORKS! Thank you so so much! I will add that if the file name you want to create is not a number, use "As String" instead of "As Long" in the first line otherwise you will get a "Runtime Error 13". Also if it helps, below is the VBA code so you can copy-paste and not be like me literally re-typing everything he has on the screen. Just pay attention to anything in {{ }}: Sub GetPDF() Dim {{merge field}} As String, file_path, folder_path As String folder_path = "C:\Users\{{Username}}\{{other folders}}" If Dir(folder_path, vbDirectory) = "" Then MkDir (folder_path) End If Dim masterDoc As Document, singleDoc As Document, lastRecordNum As Long Set masterDoc = ActiveDocument masterDoc.MailMerge.DataSource.ActiveRecord = wdLastRecord lastRecordNum = masterDoc.MailMerge.DataSource.ActiveRecord masterDoc.MailMerge.DataSource.ActiveRecord = wdFirstRecord Do While lastRecordNum > 0 masterDoc.MailMerge.Destination = wdSendToNewDocument masterDoc.MailMerge.DataSource.FirstRecord = masterDoc.MailMerge.DataSource.ActiveRecord masterDoc.MailMerge.DataSource.LastRecord = masterDoc.MailMerge.DataSource.ActiveRecord masterDoc.MailMerge.Execute False {{merge field}} = masterDoc.MailMerge.DataSource.DataFields("{{merge field}}").Value Set singleDoc = ActiveDocument singleDoc.SaveAs2 FileName:=folder_path & "\" & {{merge field}} & ".docx", FileFormat:=wdFormatXMLDocument singleDoc.ExportAsFixedFormat OutputFileName:=folder_path & "\" & {{merge field}} & ".pdf", ExportFormat:=wdExportFormatPDF singleDoc.Close False If masterDoc.MailMerge.DataSource.ActiveRecord >= lastRecordNum Then lastRecordNum = 0 Else masterDoc.MailMerge.DataSource.ActiveRecord = wdNextRecord End If Loop End Sub
THIS WORKS! Thank you so so much! I will add that if the file name you want to create is not a number, use "As String" instead of "As Long" in the first line otherwise you will get a "Runtime Error 13".
Also if it helps, below is the VBA code so you can copy-paste and not be like me literally re-typing everything he has on the screen. Just pay attention to anything in {{ }}:
Sub GetPDF()
Dim {{merge field}} As String, file_path, folder_path As String
folder_path = "C:\Users\{{Username}}\{{other folders}}"
If Dir(folder_path, vbDirectory) = "" Then
MkDir (folder_path)
End If
Dim masterDoc As Document, singleDoc As Document, lastRecordNum As Long
Set masterDoc = ActiveDocument
masterDoc.MailMerge.DataSource.ActiveRecord = wdLastRecord
lastRecordNum = masterDoc.MailMerge.DataSource.ActiveRecord
masterDoc.MailMerge.DataSource.ActiveRecord = wdFirstRecord
Do While lastRecordNum > 0
masterDoc.MailMerge.Destination = wdSendToNewDocument
masterDoc.MailMerge.DataSource.FirstRecord = masterDoc.MailMerge.DataSource.ActiveRecord
masterDoc.MailMerge.DataSource.LastRecord = masterDoc.MailMerge.DataSource.ActiveRecord
masterDoc.MailMerge.Execute False
{{merge field}} = masterDoc.MailMerge.DataSource.DataFields("{{merge field}}").Value
Set singleDoc = ActiveDocument
singleDoc.SaveAs2 FileName:=folder_path & "\" & {{merge field}} & ".docx", FileFormat:=wdFormatXMLDocument
singleDoc.ExportAsFixedFormat OutputFileName:=folder_path & "\" & {{merge field}} & ".pdf", ExportFormat:=wdExportFormatPDF
singleDoc.Close False
If masterDoc.MailMerge.DataSource.ActiveRecord >= lastRecordNum Then
lastRecordNum = 0
Else
masterDoc.MailMerge.DataSource.ActiveRecord = wdNextRecord
End If
Loop
End Sub
Thank you it might help others
Can you make this video in python laguage.
It is already there sir, just brouse my channel video no 12
how can I get that code ?
thank you
Your email ??
Tried this but it is giving me 5487 cannot complete due to permission
Not sure if any restriction. You may check options an security..
Hi can i have the code. Thank you
It is same as in the video.. thank you :)