Fix Excel VBA Macros Failing After Moving XLSM Files
Question details
The user is experiencing broken links and macro execution failures after moving an XLSM file to a different OneDrive folder.
- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Moving a macro-enabled workbook (XLSM) to a new directory or syncing it to a new OneDrive folder, then attempting to run macros.
- Observed behavior
- Macros fail to run from the custom Ribbon with broken link errors, and exporting new documents via VBA fails when trying to save.
Before proceeding, ensure your XLSM file is fully synced to its new location on OneDrive and that macros are enabled in your Excel Trust Center settings.
Test Code and Recreate Ribbon Customizations
Use this solution to verify if the macro code itself is intact and fix broken file paths in your Excel Ribbon buttons.
When an XLSM file is moved, the custom Ribbon buttons assigned to its macros often retain the old file path. This causes the button to break even if the underlying VBA code is perfectly fine.
Open your moved XLSM file in Excel. Press Alt + F11 to open the Visual Basic Editor. Locate your macro and run it directly by pressing F5. If it works here, the issue is strictly with the Ribbon link.
Go to File > Options > Customize Ribbon.
In the right pane, locate the custom group containing your broken macro button, select it, and click 'Remove'.
In the left pane, change the 'Choose commands from' dropdown to 'Macros'. Select your macro from the list, select your custom group on the right pane, and click 'Add' to map it to the new file path. Click OK to save.
Update VBA Code to Use SaveAs for New Documents
Apply this fix if your macro generates a new output document but crashes when attempting to save it.
Experience Stable Macro Execution with WPS Office
If you are tired of dealing with broken Ribbon mappings and macro errors when moving XLSM files across folders, WPS Office offers a highly compatible and lightweight alternative for your spreadsheet needs.
- 1. Download and Install: Visit the official website to download the free WPS Office suite and complete the quick installation.
- 2. Open Your XLSM File: Launch WPS Spreadsheets and open your existing macro-enabled workbook directly.
- 3. Enable Macros: Follow the prompt to enable macros, allowing your VBA scripts to run seamlessly in the new environment.

Frequently Asked Questions
Why does my Excel macro stop working when I move the file?
When you move an XLSM file to a new folder or OneDrive directory, custom Ribbon buttons mapped to macros in that file continue to point to the old file path. Clicking the button triggers a broken link error because Excel cannot find the file at the original location.
How can I tell if my VBA code is broken or if it's just the Ribbon button?
You can isolate the issue by opening the Visual Basic Editor (press Alt + F11), selecting your macro, and pressing F5 to run it directly. If it runs successfully from the editor but not from the Ribbon, your code is fine, and only the Ribbon customization needs to be recreated.
Why do I get a VBA error when saving a newly created document?
If your VBA macro generates a brand-new document, it does not have an assigned file path or filename yet. Using the standard .Save command will trigger an error. You must use .SaveAs and specify a designated file path and name.




