Fix Corrupted PDF Files After Repeated Excel VBA Exports
Question details
Determine why an Excel VBA macro produces corrupted PDF reports after repeated exports.
- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- A macro repeatedly calls ExportAsFixedFormat to generate more than 200 PDF reports.
- Observed behavior
- Exports work initially, but after approximately 160 files the macro begins producing unreadable PDFs of around five kilobytes. Disabling email does not resolve the issue, and CPU usage increases.
Locate the complete macro, including the ExportAsFixedFormat call and any code that opens workbooks or creates objects. Prepare a test output folder and note which report first produces an unreadable PDF.
Test PDF exports in smaller batches and monitor resources
Use smaller batches to identify whether the failure depends on the number of exports, a particular report, or resource usage.
In the VBA editor, temporarily limit the export loop to a smaller range, such as 50 reports, and run the macro using Run > Run Sub/UserForm. Open several PDFs from the test output folder.
Change the loop to export reports around the first failure point into the test folder. Compare a report exported on its own with the same report exported after a long run.
Open the operating system's process monitor while the macro runs and watch Excel's CPU and memory usage. Record the export number when usage rises or the first unreadable PDF appears.
Add logging around ExportAsFixedFormat to record the report number, output path, and any VBA error number and description. Check the resulting PDFs in a PDF viewer; file size alone does not prove corruption.

Review the Excel VBA export loop and object cleanup
Use this approach when repeated runs suggest a macro, workbook, or resource-handling issue.
Export Spreadsheet Reports to PDF with WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface for opening spreadsheets and exporting reports to PDF. It supports common Microsoft Office formats for easier migration, but it does not repair an Excel VBA macro.

Frequently Asked Questions
Why do the PDFs become unreadable only after many exports?
The cause cannot be determined without inspecting the macro and workbook. Test smaller batches and monitor Excel's CPU and memory to distinguish a repeated-run issue from a particular report failure.
Does a five-kilobyte PDF always mean the export is corrupted?
No. A small PDF can be valid. Open the file in a PDF viewer and compare it with a working export to verify whether it is readable and complete.
What should I log around ExportAsFixedFormat?
Record the report number, output path, and any VBA error number and description around the export call. This helps identify the first failure and whether Excel reports an error.
Will repairing Office fix the macro?
Not necessarily. Office repair may help with an installation issue, but it does not correct errors in the macro, workbook content, or resource handling.
Can WPS Office repair this Excel VBA export problem?
No. WPS Office is an alternative for working with spreadsheets and exporting PDFs; diagnosing the existing Excel VBA macro requires reviewing and testing it in Excel.




