logo
search
VBA & Macro Problems

Fix Excel VBA Macros Failing After Moving XLSM Files

Maira MehtabMaira Mehtab Sep 22, 2026 869 views

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 you start

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.

Solution 1Recommended

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.

1
Test the Macro in the Visual Basic Editor

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.

2
Open Ribbon Options

Go to File > Options > Customize Ribbon.

3
Remove the Broken Link

In the right pane, locate the custom group containing your broken macro button, select it, and click 'Remove'.

4
Recreate the Ribbon Button

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.

Ribbon Path Updated: Your Ribbon button is now mapped to the current location of the XLSM file and should trigger the macro successfully.
Free Microsoft Office alternative

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. 1. Download and Install: Visit the official website to download the free WPS Office suite and complete the quick installation.
  2. 2. Open Your XLSM File: Launch WPS Spreadsheets and open your existing macro-enabled workbook directly.
  3. 3. Enable Macros: Follow the prompt to enable macros, allowing your VBA scripts to run seamlessly in the new environment.
Fully compatible with Microsoft Excel (.xlsx and .xlsm) file formats.Reliable and stable macro execution without complicated path mapping issues.Free and lightweight suite with a familiar, easy-to-navigate user interface.Seamless file management that prevents broken links during local or cloud transfers.
microsoft office alternative - wps office

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.