VBA & Macro Problems

Fix Excel for Mac VBA Error 9: File Extensions in Workbook References

Elise WilliamsElise Williams Nov 13, 2026 870 views

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.

Fix Excel for Mac VBA Error 9: File Extensions in Workbook References
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 start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In Excel for Mac, click Developer > Visual Basic, or press Option+F11, to open the VBA editor.

2
Locate the failing reference

In the macro, find the line that raises Run-time error 9, such as Workbooks("BookName.xlsm").Activate or Windows("BookName.xlsm").Activate.

3
Adjust the Windows collection reference

For a Windows("") reference, remove the file extension and use the workbook window name, for example Windows("BookName").Activate.

4
Keep the extension for Workbooks collection

For a Workbooks("") reference, keep the full file name including the extension, for example Workbooks("BookName.xlsm").Activate.

5
Save and run the macro

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.

Check and Adjust Workbook and Window References for File Extensions
Reference corrected: After matching the collection to the correct naming convention, the macro should activate the workbook without Run-time error 9.
Free Microsoft Office alternative

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.

Free spreadsheet application with a familiar Excel-like ribbon and workflowOpens and saves .xlsx, .xlsm, and .csv files for Microsoft Office format compatibilityLightweight and easy to install on macOS and WindowsReduces platform-specific workbook-name reference interruptions for everyday spreadsheet workSeamless migration from Microsoft Excel for existing workbooks, formulas, and templates
microsoft office alternative - wps office

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.