How to Generate PDF from Mail Merge | Mail Merge Save Separate Files | Mail Merge to PDF and Doc
ฝัง
- เผยแพร่เมื่อ 11 ก.ค. 2024
- #mailmerge #mailmergetopdf #mailmergesavesapratefiles #singlefileforeachrow #pdffromexcel
00:00 Intro How to use Mail Merge to Generate PDF
02:00 How to Setup Mail Merge Template to Get PDF
03:00 Mail Merge to Get Separate file for each record
07:00 Mail Merge to Separate PDF from Excel Data
10:00 Mail Merge Get Separate PDF for each row in excel - วิทยาศาสตร์และเทคโนโลยี
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
Hi can i have the code. Thank you
It is same as in the video.. thank you :)
Tried this but it is giving me 5487 cannot complete due to permission
Not sure if any restriction. You may check options an security..
how can I get that code ?
thank you
Your email ??