Fix Excel for Mac Runtime Error 1004 When Creating XML Files
Question details
Users encounter a Visual Basic Runtime Error 1004 when executing a macro to generate an XML file on Mac, despite the same code working perfectly in Windows.
- Product
- Excel 2024 for Mac
- Device & OS
- Mac
- Scenario
- Running a VBA macro designed to generate and save an XML file within Excel for Mac.
- Observed behavior
- The macro execution fails and triggers a Visual Basic Runtime Error 1004, halting the XML file creation process.
Before troubleshooting, ensure you have backed up your original workbook. You should also open the VBA Editor to identify the exact line of code triggering the runtime error.
Create a Sanitized Sample Workbook for Troubleshooting
Isolate the issue by creating a minimal file without sensitive data to safely test the macro and workbook structure in a Mac environment.
Because runtime error 1004 on a Mac is frequently caused by environment-specific variables or file path syntax differences in VBA, support experts need to test the actual code. Creating a sanitized sample workbook ensures your confidential information remains secure while allowing others to accurately reproduce the error.
Make a copy of your original Excel workbook to ensure your actual data remains intact during the troubleshooting process.
Open the copied workbook and delete any sensitive personal, financial, or proprietary data. Replace necessary data points with dummy text if the macro requires data to run.
Remove any unrelated VBA modules, user forms, or scripts. Keep only the specific code required to create the XML file and reproduce the runtime error 1004.
Upload the minimal sample workbook to a secure cloud storage service (such as OneDrive, Google Drive, or Dropbox). Generate a shareable link and provide it to the support community.
Verify File Path Separators in VBA Code
Ensure your VBA code uses the correct file path separators for macOS, which is a common cause for Error 1004 when saving files.
Experience Seamless Spreadsheet Management with WPS Office
If you are tired of dealing with platform-specific VBA runtime errors and compatibility issues in Microsoft Excel for Mac, consider switching to WPS Office. It provides a lightweight, highly compatible alternative for your daily spreadsheet and data management needs.
- 1. Download and Install: Visit the official WPS website to download the Mac version and complete the quick, lightweight installation.
- 2. Open Your Workbooks: Launch WPS Office and open your existing spreadsheet files directly without needing any format conversion.
- 3. Edit and Save: Enjoy a smooth, crash-free editing experience and save your work securely in standard formats.

Frequently Asked Questions
Why does VBA code that works on Windows throw Error 1004 on Mac?
Mac and Windows use different file systems and path separators. Macros attempting to save, open, or create files using Windows-style backslashes (\) will fail to locate the directory on a Mac, resulting in Runtime Error 1004.
What exactly is a sanitized workbook?
A sanitized workbook is a stripped-down copy of your Excel file with all sensitive, personal, or confidential data removed. It retains only the structural elements and minimal VBA code necessary to demonstrate the error you are experiencing.
How do I share a sample workbook securely for community troubleshooting?
After sanitizing your file, upload it to a secure cloud storage provider like OneDrive, Google Drive, or Dropbox. Create an anonymous sharing link (ensuring edit access if necessary) and share that URL in your support forum post.




