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
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 10

  • @JeffFahndrich
    @JeffFahndrich ปีที่แล้ว +4

    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

    • @Python2020
      @Python2020  ปีที่แล้ว

      Thank you it might help others

  • @cpkanojiya
    @cpkanojiya ปีที่แล้ว +1

    Can you make this video in python laguage.

    • @Python2020
      @Python2020  ปีที่แล้ว

      It is already there sir, just brouse my channel video no 12

  • @litolapis9691
    @litolapis9691 5 หลายเดือนก่อน +1

    Hi can i have the code. Thank you

    • @Python2020
      @Python2020  5 หลายเดือนก่อน

      It is same as in the video.. thank you :)

  • @kaira7793
    @kaira7793 หลายเดือนก่อน

    Tried this but it is giving me 5487 cannot complete due to permission

    • @Python2020
      @Python2020  หลายเดือนก่อน +1

      Not sure if any restriction. You may check options an security..

  • @supatkhongfak3661
    @supatkhongfak3661 ปีที่แล้ว +1

    how can I get that code ?
    thank you