See how we can create custom letters in pdf format using the data we have in excel and a word template. In this example, we have a Name field in pdf which is picked from excel and personalized letters are generated through the macro.
Subscribe to my channel to support!
You can ask questions in comments section…..(read more)
Convert Word 2 PDF: Word to PDF Converter
Convert PowerPoint 2 PDF: PPT to PDF Converter
Convert Excel 2 PDF: Excel to PDF Converter
Convert an Image 2 PDF: Image to PDF Converter
Convert HTML 2 PDF: HTML to PDF Converter
More Tools: PDF Converter
Hey Kamal, My VBA just Run-Time Error '91': Object Variable or With Block Variable Not Set , can you help me ?
Sub CreatePDFs()
Dim wd As Word.Application
Dim doc As Word.Document
Set wd = New Word.Application
wd.Visible = False
For i = 2 To 7
Set doc = wd.Documents.Open("C:UsersJoyOneDriveDocumentsTest Teamplate HÐLÐ.docx")
With wd.Selection.Find
.Text = "<<name>>"
.Replacement.Text = Cells(i, 1).Value
.Execute Replace:=wdReplaceAll
End With
doc.ExportAsFixedFormat OutputFileName:=ActiveWorkbook.Path & "/" & Cells(i, 2).Value & "_" & Cells(i, 1).Value & ".pdf", _
ExportFormat:=wdExportFormatPDF
Application.DisplayAlerts = False
doc.Close SaveChanges:=False
Application.DisplayAlerts = True
Next
wd.Quit
End Sub
Hi.. I jus copied ur code.. pdf is getting created.. however none of the fields are merged.. what am I missing here.. can you help me.. thanks in advance.
Exactly what I was looking for. Can't tell you how happy I am to have found this video!
Thank you very much. I wrote the code but I think there's a lot of error. I wish I could've sent ss
Very very good, used it already. Thank u very much.
Love the video! thank you! I seem to get stuck at wd.Selection.Find – giving this error: Object variable or with block variable not set. Please help!!!
Very helpful. Simple and solid solution. Thank you very much!
This video is very helpful
May I know why there is a compile error "Next without For"?
Sub CreatePDFs()
Dim wd As Word.Application
Dim doc As Word.Document
Set wd = New Word.Application
wd.Visible = True
For i = 2 To 7
Set doc = wd.Documents.Open("C:UsersENGDocumentsTTCExcelTest 1 – mail merge from Excel to Words and save in PDFTest 1 template – 20220331.docx")
With wd.Selection.Find
.Text = "<<Name>>"
.Replacement.Text = Cells(i, 1).Value
.Execute Replace:=wdReplaceAll
doc.ExportAsFixedFormat OutputFileName:=ActiveWorkbook.Path & "/" & Cells(i, 2).Value & "_" & Cells(i, 1).Value & ".pdf", _
ExportFormat:=wdExportFormatPDF
Application.DisplayAlerts = False
doc.Close SaveChanges:=False
Application.DisplayAlerts = True
Next
wd.Quit
End Sub
Hi Kamal, what if in my Word doc, there are more than one mail merge field, then how do I set the macro to include these fields to replace in every subsequent pdf?
Hi I pretty much copied your code exactly and got a compile error. can you please help?
Thank you sir, this is very helpful! I have just one doubt- is it possibile to save pdf(s) by selecting a folder using the Application.FileDialog(msoFileDialogFolderPicker)? I'm trying with no success
Can you please help how to make the for loop dynamic
Sir,
I need this coding file
hi can you please guide to save with header and footer of the word, in the current above code header is not getting saved
Hi I have a image in word and want to add different name on that image. So I add text box. But when I run the macro all pdf show same name. Pls help
You have webscraping for google chrome using Excel VBA? I tried using downloading Selenium but keep getting an error, I believe it may have been selenium download, google driver issues since I’ve read there’s issue with that? I’ve read Selenium has compatibility with Chrome old drivers?
Even someone else in Github wrote a Selenium VBA code, and tried using that one, yet, didn’t work. dont know how to fix the issue.
I’ve even completely uninstalled Chrome and installed Chrome again to begin from scratch, yet, kept getting error.
If you can show the options using Selenium and how to download Selenium? And or if there are alternatives? Thx!
Your WhatsApp number please
Hi thanks for the nice video..I need to attach pdf copies to the word doc template and then use the mail merge to send out mass emails I m able to create the emails using mailmerge and list but unable to add PDFs can you plz help..
sir if the name column has first name and surname and i want pdf to be saved with only first name and unique id only, then what should i do.