Fix VBA Read-Only Property Error When Saving Excel as PDF
Question details
The user is attempting to save an Excel invoice as a PDF using a VBA macro but encounters a read-only property error.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Running a VBA macro script to generate and export an active sheet or invoice as a PDF file.
- Observed behavior
- The macro execution halts, displaying a "Can't assign to read-only property" error, typically due to incorrect variable assignments, omitted properties, or invalid file paths.
Before editing your VBA code, verify that the destination folder on your drive actually exists, you have write permissions to it, and the target PDF filename is not currently open in another application.
Explicitly Define Values and Concatenate the PDF Extension
Use this solution to correct how VBA reads cell data and constructs the final output file name, avoiding read-only object conflicts.
The "Can't assign to read-only property" error often triggers when you try to assign a value to an object without specifying its property, or when string concatenation for the file path is improperly formatted.
Press Alt + F11 in Excel to open the VBA Editor, and locate the macro script responsible for exporting the PDF.
Ensure you are explicitly reading the cell contents by adding '.Value' to your range assignments. For example: InvoiceLetter = Range("G1").Value and InvoiceNumber = Range("H1").Value.
Construct the file name variable by concatenating the parsed values with the '.pdf' string: fName = InvoiceLetter & InvoiceNumber & ".pdf".
Use the ActiveSheet.ExportAsFixedFormat method and properly concatenate the folder path (sPath) with the filename (fName): ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sPath & fName.

Verify Folder Path and Backslash Formatting
Use this step if the macro continues to fail after variables are corrected, indicating an issue with the destination path string.
Run Macros and Export to PDF Seamlessly with WPS Office
WPS Office provides robust native support for VBA and macros, allowing you to automate tasks like saving invoices to PDF without hassle. Its Spreadsheet tool integrates directly with your existing code.
- 1. Open Your Macro File: Launch WPS Spreadsheets and open your .xlsm file containing the invoice macro.
- 2. Access the VBA Editor: Navigate to the 'Developer' tab and click on 'Macros', or press Alt+F11 to open the built-in VBA editor.
- 3. Run Your Script: Edit your path or variables as needed, and execute the VBA script to automatically export your active sheets as PDF files.

Frequently Asked Questions
Why does VBA throw a 'Can't assign to read-only property' error?
This error occurs when you attempt to change a property that can only be read (not written to), or when you omit a specific property (like .Value) causing VBA to mistakenly try to overwrite the default object structure.
How do I correctly format the file path for ExportAsFixedFormat in VBA?
Ensure your path string includes the drive letter, valid folder names, ends with a backslash (\), and is concatenated properly with the filename and the .pdf extension using the ampersand (&) operator.
Can I save as PDF using VBA without installing third-party add-ins?
Yes, modern spreadsheet applications like Microsoft Excel and WPS Office natively support the ActiveSheet.ExportAsFixedFormat method, allowing direct PDF saving via VBA code without extra plugins.




