How to Fix Word VBA InsertFile Error 5097 After Microsoft 365 Updates
Question details
Users encounter Runtime Error 5097 when executing a VBA macro that uses the InsertFile method to insert DOCX or Word XML files.

- 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.
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.
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.
Launch Microsoft Word and open a blank document. Click on 'File' in the top-left corner, then select 'Account' from the left sidebar.
Under the 'Product Information' section, click on the 'Update Options' dropdown menu located next to 'Office Updates'.
Select 'Update Now'. Microsoft Office will check for, download, and install the latest available patches.
Once the update is complete, restart Microsoft Word, open your macro-enabled template, and run the VBA script to verify the InsertFile method works.

Roll Back to an Earlier Stable Office Build
If you are unable to install the latest updates or if your organization restricts patch deployment, you can temporarily roll back Office 365 to a previous stable build (like Version 2207).
Save the Target Document in the Legacy DOC Format
Since the InsertFile bug strictly targets modern XML-based files (.docx), changing the source document to a legacy format (.doc) acts as a quick workaround without touching system updates.
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. Download and Install: Download WPS Office from the official website and complete the quick installation.
- 2. Open Your Document: Launch WPS Writer and open your macro-enabled DOCM or DOTM template.
- 3. Run Your Macro: Navigate to the Developer tab, enable macros, and execute your VBA code seamlessly.

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.




