VBA & Macro Problems

How to Fix Word VBA InsertFile Error 5097 After Microsoft 365 Updates

Muhammad TalhaMuhammad Talha Oct 23, 2026 870 views

Question details

Users encounter Runtime Error 5097 when executing a VBA macro that uses the InsertFile method to insert DOCX or Word XML files.

How to Fix Word VBA InsertFile Error 5097 After Microsoft 365 Updates
Product
Microsoft Word 365
Device & OS
not provided
Scenario
Running an automated VBA macro designed to insert external document contents into a master Word document.
Observed behavior
The VBA macro abruptly fails and returns Runtime Error 5097. However, manually inserting text from a file, or using VBA to insert legacy DOC and ODT files, still works perfectly.
Before you start

Check your current Microsoft Word build by navigating to File > Account. Close all active Word documents and back up your template files before applying updates or rolling back your Office installation.

Solution 1Recommended

Install the Latest Microsoft Office Updates

Microsoft identified this issue as a regression bug and resolved it in later updates (version 2302 and above). Updating Office is the recommended permanent fix.

Because this error is caused by a specific flaw in the Office 365 update cycle (starting around version 2208), the most reliable way to restore DOCX functionality to the InsertFile method is to patch the software to a newer, stable release.

1
Open Word Account Settings

Launch Microsoft Word and open a blank document. Click on 'File' in the top-left corner, then select 'Account' from the left sidebar.

2
Check for Updates

Under the 'Product Information' section, click on the 'Update Options' dropdown menu located next to 'Office Updates'.

3
Apply Updates

Select 'Update Now'. Microsoft Office will check for, download, and install the latest available patches.

4
Restart and Test

Once the update is complete, restart Microsoft Word, open your macro-enabled template, and run the VBA script to verify the InsertFile method works.

Install the Latest Microsoft Office Updates
Update Confirmation: Ensure your Office build updates to Version 2302 or later, as earlier builds may still contain the bug.
Free Microsoft Office alternative

Avoid Update Regressions with WPS Office

Microsoft Office updates can occasionally introduce frustrating bugs like VBA Error 5097 that halt your workflow. If you need a stable, highly compatible alternative, consider WPS Office. It provides full support for VBA macros, ensuring your automated workflows run smoothly without being disrupted by unpredictable update regressions.

  1. 1. Download and Install: Download WPS Office from the official website and complete the quick installation.
  2. 2. Open Your Document: Launch WPS Writer and open your macro-enabled DOCM or DOTM template.
  3. 3. Run Your Macro: Navigate to the Developer tab, enable macros, and execute your VBA code seamlessly.
Fully compatible with Microsoft Word DOC, DOCX, and DOTM formats.Robust built-in support for VBA macros and automated scripts.Lightweight architecture for fast installation and smooth performance.Free to use with a familiar, intuitive user interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why does the VBA InsertFile method work for DOC but not DOCX?

The runtime error 5097 is caused by a specific regression bug in a Microsoft 365 update (around Version 2208). This bug specifically breaks the InsertFile method for modern XML-based formats like DOCX and Word XML, while leaving legacy binary formats like DOC and ODT completely unaffected.

Is Runtime Error 5097 a sign of document corruption?

No. Extensive testing confirms that Error 5097 during a VBA InsertFile operation is an Office 365 software bug, not document corruption. If you manually insert the text or save the 'failing' DOCX as a DOC file, it will work perfectly.

How do I check which Office version is causing the VBA error?

You can check your current build by opening Word and navigating to File > Account. Look under 'Product Information' for the version number. The bug generally appears in builds following Version 2207, specifically starting around Build 15601.20088.

Does manually inserting text from a file still work?

Yes. The bug is strictly limited to the VBA programmatic InsertFile method. Manually clicking Insert > Object > Text from File functions normally even on the affected Microsoft 365 versions.