Fix Excel for Mac VBA Error 9: File Extensions in Workbook References
Question details
The user needs to understand why Excel for Mac raises Run-time error 9 when a VBA macro uses file extensions in workbook or window references, and how to write cross-platform workbook code.

- Product
- Microsoft Excel for Mac
- Device & OS
- macOS
- Scenario
- A VBA macro that references a workbook or window by name fails on Excel for Mac, and the user needs it to run reliably on both Mac and Windows.
- Observed behavior
- Run-time error 9 appears when a macro uses a file extension in a Windows-style workbook or window reference, while the same code may work differently on Windows.
Before you edit the macro, note the exact workbook and window names in the failing line and confirm whether the workbook is saved as .xlsm, .xlsx, or another format. Also check your Excel for Mac version, because the required reference format can change after an Office update.
Check and Adjust Workbook and Window References for File Extensions
Use this first when a macro works in Windows but throws Run-time error 9 in Excel for Mac at a line that refers to a workbook or window by name.
Excel for Mac and Windows can resolve workbook and window names differently. A reference that includes a file extension may be valid in one collection but not in another, especially after an Office update.
In Excel for Mac, click Developer > Visual Basic, or press Option+F11, to open the VBA editor.
In the macro, find the line that raises Run-time error 9, such as Workbooks("BookName.xlsm").Activate or Windows("BookName.xlsm").Activate.
For a Windows("") reference, remove the file extension and use the workbook window name, for example Windows("BookName").Activate.
For a Workbooks("") reference, keep the full file name including the extension, for example Workbooks("BookName.xlsm").Activate.
Save the macro, run it in Excel for Mac, and verify the reference now activates the correct workbook. If it still fails, test the same workbook on Windows.

Replace Hard-Coded Workbook Names with Object Variables
Use this for cross-platform macros that need to run reliably on both Mac and Windows without filename differences.
Test Macros on Both Platforms After Office Updates
Use this when an existing macro suddenly fails on one platform after an update, to isolate platform-specific reference behavior.
Avoid Excel for Mac VBA Reference Errors with WPS Office
If Excel for Mac keeps throwing Run-time error 9 on workbook references, WPS Office gives you a free, lightweight spreadsheet alternative that opens and saves Excel files, keeps a familiar interface, and handles everyday workbook tasks without the same platform-specific VBA naming issues.

Frequently Asked Questions
Why does Excel for Mac raise Run-time error 9 when a macro uses a file extension in a workbook reference?
The error usually appears when the macro uses a file extension in a Windows("") reference. In some Mac Excel versions, Windows("BookName").Activate needs the workbook window name without the extension, while Workbooks("BookName.xlsm").Activate still needs the extension. Check the exact line and test both forms.
Will I have to remove extensions from all my other macros on this Mac?
Not necessarily. Only references that use the Windows collection may need the extension removed. Workbooks collection references usually keep the file extension. Review each failing macro rather than changing every workbook reference.
Will macros still work on Windows if I remove file extensions from Windows() references?
In most cases yes, because the window name on Windows also normally appears without the file extension. However, test the macro on both Windows and Mac, and prefer ThisWorkbook or ActiveWorkbook instead of hard-coded names for cross-platform reliability.
How can I avoid this error entirely in cross-platform VBA code?
Open the VBA editor with Developer > Visual Basic or Option+F11, then replace hard-coded workbook names with object variables such as Set wb = ThisWorkbook or Set wb = ActiveWorkbook. This avoids filename and extension differences between Mac and Windows.
Does WPS Office support Excel files with VBA macros?
WPS Office opens and saves Excel-compatible .xlsm and .xlsx files. If you move macros between WPS Office and Microsoft Excel, test the same workbook and window references on the target platform because macro behavior can vary by version and platform.




