Export Report Worksheets from Multiple Excel Files to PDF with VBA
Question details
Export only the Report worksheet from each Excel workbook in a date-based folder to a separate, one-page PDF.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A daily batch of workbooks is stored in a folder named for the date, and each Report worksheet needs its own PDF.
- Observed behavior
- The desired result is one PDF per workbook, scaled to one page, without saving changes to the source workbooks.
Place the source workbooks in a folder named with today's date in yyyy-mm-dd format, and confirm the sheets are named Report. Save the macro in a separate macro-enabled workbook and replace the example base path in the code with your actual folder path.
Use Excel VBA to export each Report worksheet as a one-page PDF
Run this macro when the workbooks are grouped in a folder named for the current date.
The macro exports the used range of each Report sheet, skips workbooks without that sheet, and saves PDFs beside the source files. Existing PDFs with the same names may be overwritten. If unwanted blank pages or columns appear, check the sheet's used range and formatting.
In Excel, open a separate workbook and save it as an Excel Macro-Enabled Workbook (.xlsm). Open Developer > Visual Basic, then choose Insert > Module.
Paste the following code into the module. Replace /path/to/reports with the parent folder containing the dated folders, using the path format for your system and no trailing separator: Sub ExportReportsToPDF() Dim basePath As String, folderPath As String Dim fileName As String, pdfName As String Dim files As Collection, item As Variant Dim wb As Workbook, ws As Worksheet Dim oldSecurity As Long, errorMessage As String basePath = "/path/to/reports" folderPath = basePath & Application.PathSeparator & Format(Date, "yyyy-mm-dd") If Dir(folderPath, vbDirectory) = "" Then MsgBox "Folder not found: " & folderPath, vbExclamation Exit Sub End If Set files = New Collection fileName = Dir(folderPath & Application.PathSeparator & "*.xls*") Do While fileName <> "" If Left(fileName, 2) <> "~$" Then files.Add fileName fileName = Dir() Loop oldSecurity = Application.AutomationSecurity On Error GoTo Failed Application.AutomationSecurity = 3 ' Disable macros in opened workbooks. For Each item In files Set wb = Workbooks.Open(Filename:=folderPath & Application.PathSeparator & CStr(item), UpdateLinks:=0, ReadOnly:=True) Set ws = Nothing On Error Resume Next Set ws = wb.Worksheets("Report") On Error GoTo Failed If Not ws Is Nothing Then With ws.PageSetup .PrintArea = ws.UsedRange.Address .Zoom = False .FitToPagesWide = 1 .FitToPagesTall = 1 End With pdfName = Left(CStr(item), InStrRev(CStr(item), ".") - 1) & ".pdf" ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=folderPath & Application.PathSeparator & pdfName, IgnorePrintAreas:=False End If wb.Close SaveChanges:=False Set wb = Nothing Next item GoTo CleanUp Failed: errorMessage = Err.Description CleanUp: On Error Resume Next If Not wb Is Nothing Then wb.Close SaveChanges:=False Application.AutomationSecurity = oldSecurity On Error GoTo 0 If errorMessage <> "" Then MsgBox "Export stopped: " & errorMessage, vbExclamation Else MsgBox "Export complete. Check the dated folder for PDFs.", vbInformation End If End Sub
In Excel, choose Developer > Macros, select ExportReportsToPDF, and click Run. Open the dated folder and verify that each expected PDF contains the Report sheet on one page.
Use your operating system's scheduling tool to open the macro workbook and run the macro each day, or open the workbook and run it manually. Test the scheduled process with Excel and the required macro permissions before relying on it.

Work with Excel reports in WPS Spreadsheet
WPS Office is a free, lightweight alternative with a familiar interface for opening and editing Excel reports. Its format compatibility makes it easy to move existing spreadsheets into WPS; the Excel VBA automation above still requires Microsoft Excel.

Frequently Asked Questions
How do I change the dated folder format?
In the macro, change Format(Date, "yyyy-mm-dd") to match your folder names. For example, use Format(Date, "yyyymmdd") for a folder named 20260504.
What happens if a workbook has no Report sheet?
The macro skips its PDF export and closes the workbook without saving. Check the sheet tab name if an expected PDF is missing.
Can I export a different worksheet?
Yes. In the VBA module, replace "Report" in wb.Worksheets("Report") with the exact name of the worksheet you want to export.
Will the macro run automatically every day?
Not by itself. Run it from Developer > Macros each day, or configure and test an operating-system scheduled task that opens the macro workbook and runs the procedure.
Why is the PDF text so small?
The macro sets both FitToPagesWide and FitToPagesTall to 1, so Excel shrinks the used range to a single page. Review the sheet's formatting and used range, or adjust its Page Layout settings if one-page output is not essential.




