No Limit with Excel VBA & ChatGPT - Part 1: Bulk PDF Converter This script automatically converts files in a designated folder to PDF: Create a folder & copy its file path Paste path into the folderPath variable in the VBA code, replacing "C:\Users\...": Sub ConvertAllFilesToPDF() Dim folderPath As String Dim fileName As String, fileExt As String Dim fullPath As String, pdfPath As String Dim converted As Boolean Dim wdApp As Object, wdDoc As Object Dim xlApp As Object, xlWB As Object Dim ppApp As Object, ppPres As Object ' Set your folder path here folderPath = "C:\Users\" ' Replace with your folder path ' Ensure the path ends with a backslash If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\" ' Start reading files in the folder fileName = Dir(folderPath) ' Process each file in the folder Do While fileName <> "" fullPath = folderPath & fileName fileExt = LCase(Right(fileName, Len(fileName) - InStrRev(fileName, "."))) pdfPath = folderPath & Left(fileName, InStrRev(fileName, ".") - 1) & ".pdf" converted = False On Error Resume Next ' === Try Word === If Not converted And (fileExt = "doc" Or fileExt = "docx" Or fileExt = "rtf" Or fileExt = "txt") Then Set wdApp = CreateObject("Word.Application") Set wdDoc =
wdApp.Documents.Open(fullPath, ReadOnly:=True) wdDoc.ExportAsFixedFormat pdfPath, 17 wdDoc.Close False wdApp.Quit Set wdDoc = Nothing: Set wdApp = Nothing converted = True End If ' === Try Excel === If Not converted And (fileExt = "xls" Or fileExt = "xlsx" Or fileExt = "xlsm" Or fileExt = "csv") Then Set xlApp = CreateObject("Excel.Application") Set xlWB =
xlApp.Workbooks.Open(fullPath, ReadOnly:=True) xlWB.ExportAsFixedFormat 0, pdfPath xlWB.Close False xlApp.Quit Set xlWB = Nothing: Set xlApp = Nothing converted = True End If ' === Try PowerPoint === If Not converted And (fileExt = "ppt" Or fileExt = "pptx") Then Set ppApp = CreateObject("PowerPoint.Application") Set ppPres =
ppApp.Presentations.Open(fullPath, WithWindow:=False) ppPres.SaveAs pdfPath, 32 ppPres.Close ppApp.Quit Set ppPres = Nothing: Set ppApp = Nothing converted = True End If ' Log the results If converted Then Debug.Print "Converted: " & fileName Else Debug.Print "Skipped (unsupported or failed): " & fileName End If On Error GoTo 0 ' Move to the next file fileName = Dir Loop MsgBox "All eligible files have been successfully converted to PDF!", vbInformation End Sub