How to Fix Excel VBA Macro Flickering but Not Creating PDF
Question details
The user is executing an Excel VBA macro to export an invoice as a PDF, but the screen flickers and the PDF file is never created or saved.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Running an automated VBA macro to export specific spreadsheet data and save it as a PDF document into a local or OneDrive folder.
- Observed behavior
- The macro executes and causes the screen to flicker as if processing, but it finishes without saving the expected PDF file to the specified destination.
Verify that the destination folder specified in your macro actually exists on your computer and that you have the correct write permissions to save files there.
Fix OneDrive Local Sync Settings
Ensure that your OneDrive folder is available locally on your computer, as VBA cannot save directly to cloud-only placeholders without throwing an error.
When using OneDrive, files and folders might be set to 'Files On-Demand' (online-only). If a VBA macro attempts to export a PDF to an online-only directory using a local file path, the script will silently fail to find the directory.
Open Windows File Explorer and navigate to the destination folder specified in your VBA macro (for example, the 'Invoices' folder on your Desktop or OneDrive).
Right-click the folder and select 'Always keep on this device'. Wait for the status icon to turn into a solid green circle, indicating the folder is available locally.
Ensure your VBA code uses the local drive path (e.g., C:\Users\Name\OneDrive\...) rather than a OneDrive web URL (https://...).

Apply Error Handling to the VBA Code
Update your VBA script to properly use the ExportAsFixedFormat method and implement error handling so you can see exactly why the macro fails.
Automate PDF Exports Seamlessly with WPS Spreadsheet
WPS Office provides excellent support for VBA macros alongside a powerful built-in PDF converter, allowing you to run your invoice automation scripts reliably and efficiently.
- 1. Install WPS Office: Download and install the free WPS Office suite on your device.
- 2. Open your Macro Workbook: Launch WPS Spreadsheet and open your macro-enabled file (.xlsm).
- 3. Run VBA and Export: Press Alt + F11 to access the VBA Editor, verify your macro paths, and run the script to generate your PDFs flawlessly.

Frequently Asked Questions
How do I stop the screen from flickering when the VBA macro runs?
Screen flickering occurs because the application constantly redraws the screen as data changes. You can prevent this by opening the VBA editor and typing 'Application.ScreenUpdating = False' at the start of your macro, and 'Application.ScreenUpdating = True' at the end.
Why does the ExportAsFixedFormat method fail in VBA?
This method typically fails if the specified 'Filename' path does not exist, if you lack write permissions to the destination folder, or if the generated filename contains invalid characters (like / \ : * ? " < > |). Always ensure the target directory is fully created and spelled correctly.
Can OneDrive block my VBA macro from saving a file?
Yes. If the destination OneDrive folder is set to 'Files On-Demand' (online-only) or if the macro is attempting to use a web URL instead of a local file path, the VBA script will fail to locate the directory. Right-click the OneDrive folder in File Explorer and select 'Always keep on this device' to fix this.




