File Management & Batch Processing Intermediate

Excel to PDF Batch Converter

Convert multiple Excel files to PDF format with custom settings

19 views

Perfect For:

  • Report distribution
  • Document sharing
  • Archive creation
VBA Code
Sub BatchConvertToPDF()
    Dim folderPath As String
    Dim outputPath As String
    Dim fileName As String
    Dim wb As Workbook
    Dim pdfName As String
    Dim fileCount As Long

    ' Get input folder
    folderPath = InputBox("Enter folder path containing Excel files:")
    If folderPath = "" Then Exit Sub

    ' Ensure path ends with backslash
    If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\"

    ' Get output folder
    outputPath = InputBox("Enter output folder for PDF files:", "Output Folder", folderPath & "PDFs\")
    If outputPath = "" Then Exit Sub

    If Right(outputPath, 1) <> "\" Then outputPath = outputPath & "\"

    ' Create output folder if it doesn't exist
    If Dir(outputPath, vbDirectory) = "" Then
        MkDir outputPath
    End If

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    fileCount = 0
    fileName = Dir(folderPath & "*.xlsx")

    Do While fileName <> ""
        If fileName <> ThisWorkbook.Name Then
            Set wb = Workbooks.Open(folderPath & fileName)

            ' Create PDF filename
            pdfName = outputPath & Left(fileName, InStrRev(fileName, ".") - 1) & ".pdf"

            ' Export to PDF with custom settings
            wb.ExportAsFixedFormat _
                Type:=xlTypePDF, _
                fileName:=pdfName, _
                Quality:=xlQualityStandard, _
                IncludeDocProps:=True, _
                IgnorePrintAreas:=False, _
                OpenAfterPublish:=False

            wb.Close SaveChanges:=False
            fileCount = fileCount + 1
        End If

        fileName = Dir()
    Loop

    Application.ScreenUpdating = True
    Application.DisplayAlerts = True

    MsgBox "Converted " & fileCount & " Excel files to PDF!" & vbCrLf & _
           "PDFs saved to: " & outputPath
End Sub

Related Topics

pdf conversion batch export

Need Custom VBA Solutions?

Our AI-powered VBA generator can create custom code tailored to your specific requirements in seconds.

Generate Custom VBA Code

Related Templates

More VBA templates in the same category

Advanced

File Management & Batch Processing

Process multiple files and organize workbooks

View Template