How to Fix VBA Error 5097 When Updating Word Content Controls
Question details
The user needs to resolve VBA Error 5097, which occurs when running a macro to update multiple content controls while Track Changes is enabled.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Running a Word VBA macro to automatically update the text of hundreds of content controls selected by their tags.
- Observed behavior
- The macro fails with Error 5097 (application-defined or object-defined error) when Track Changes is enabled, but runs successfully when revision tracking is disabled.
Ensure you have access to the VBA Editor (Alt + F11) and save a backup copy of your document before modifying the macro code.
Temporarily Disable Track Changes in the VBA Code
Modify your macro to automatically turn off Track Changes before updating the content controls, preventing the application-defined error.
Updating a large number of content controls while Word is actively tracking revisions can cause an object-defined error. Disabling the feature during execution prevents this memory conflict and allows the procedure to run smoothly.
Press Alt + F11 on your keyboard while in Word to open the Microsoft Visual Basic for Applications window.
Locate your macro code and add `ActiveDocument.TrackRevisions = False` at the very beginning of the update routine.
Add `ActiveDocument.TrackRevisions = True` at the end of the routine to re-enable tracking after the content controls have been updated.
Save the macro and run the procedure again to confirm that Error 5097 is successfully resolved.

Verify Content Control Tag Case Sensitivity
Ensure that the tags referenced in your VBA code exactly match the tags in your document, as mismatches can trigger macro failures.
Switch to WPS Office for a Smoother Document Experience
If you frequently encounter application-defined errors and complex VBA issues in Microsoft Word, consider switching to WPS Office. It provides a lightweight, highly compatible alternative with seamless Microsoft Office format support and powerful document processing capabilities.
- 1. Download and Install: Visit the official WPS website to download the free installation package for your operating system.
- 2. Open Your Document: Launch WPS Writer and open your existing Word document to continue working seamlessly.
- 3. Edit with Ease: Enjoy a familiar interface and robust editing tools without the heavy resource usage.

Frequently Asked Questions
What does VBA Error 5097 mean in Word?
Error 5097 is an 'application-defined or object-defined error'. It indicates that the VBA code is attempting to perform an action that the application's object model cannot handle in its current state, such as processing too many tracked changes at once.
Why does Track Changes conflict with updating content controls?
When a macro updates hundreds of content controls simultaneously, having Track Changes enabled forces the application to record every single modification into memory. This can overwhelm the memory buffer and trigger an object-defined error.
Is the SelectContentControlsByTag method case-sensitive?
Yes. If your VBA code looks for a tag named 'UpdateData' but the document's content control is tagged as 'updatedata', the method will not find the control. This mismatch can lead to unexpected macro errors.
Can I track the macro's changes without getting Error 5097?
If you absolutely need to track the macro's changes, try breaking the update process into smaller batches using a loop, or inserting a `DoEvents` command in your VBA code to allow the application time to process the revisions sequentially.




