Create pdf file from ms word

Sub pdffilesfromword()
Application.ScreenUpdating = False
Dim DocName As String, PDFPath, Folderpath, From, Till, Message, fs
Folderpath = “C:Merged Letters In PDF File From Word”

Set fs = CreateObject(“Scripting.FileSystemObject”)
If fs.FolderExists(Folderpath) = False Then
fs.createfolder (Folderpath)
Else: End If

From = 1
Till = 5

Message = (Till – From) + 1

While From <= Till

ActiveDocument.MailMerge.DataSource.ActiveRecord = From
DocName = ActiveDocument.Fields(1).Result
‘CheckFilename for: ?ActiveDocument.Fields(1).Code
PDFPath = Folderpath & “” & DocName & “.pdf”
Massage = ((Till – From) + 1)

ActiveDocument.ExportAsFixedFormat OutputFileName:=PDFPath, ExportFormat:= _
wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent, IncludeDocProps:=True

From = From + 1
Wend

MsgBox (Message & ” Pdf Files Saved In = ” & Folderpath)

End Sub