Fix Word VBA Error 4198: Cross-Referencing Captions in Text Boxes
Question details
The user is attempting to use VBA to cross-reference captions located inside text boxes, but the script fails with run-time error 4198.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Running a recorded VBA macro utilizing the Document.GetCrossReferenceItems method to find and insert cross-references to captions.
- Observed behavior
- The Document.GetCrossReferenceItems method fails to return captions that are placed inside text boxes (the shape layer), resulting in run-time error 4198 (Command failed) when the script tries to reference them.
Before applying workarounds, ensure your document is saved and backed up. Modifying shapes and running custom VBA macros can sometimes alter your document's layout unexpectedly.
Manually Bookmark Captions and Insert REF Fields
Since standard Word VBA methods cannot natively detect captions residing in the shape layer, you can bypass the error by manually bookmarking the text box caption and referencing it with a field code.
Word treats text boxes as a separate 'story' layer distinct from the main document body. This architectural limitation means methods like GetCrossReferenceItems will completely ignore any captions inside them.
Click inside the text box and highlight the exact text of the caption you want to cross-reference.
Navigate to the Insert tab on the ribbon, click 'Bookmark', type a unique name without spaces (e.g., 'Fig1Caption'), and click 'Add'.
Click in the main document body where you want the reference to appear. Press Ctrl + F9 to insert empty field brackets { }, then type 'REF Fig1Caption' inside the brackets.
Right-click the field code you just created and select 'Update Field' (or press F9). The caption number or text will now appear.

Convert Text Boxes to Frames
Converting your text boxes into frames forces Word to treat the captions as part of the main document text layer, resolving the VBA limitations natively.
Try WPS Office for Seamless Document Formatting
If you are frustrated by deep architectural limitations and VBA errors in Microsoft Word, consider switching to WPS Office. It provides a lightweight, user-friendly environment for managing complex layouts, captions, and references without the steep learning curve.
- 1. Download the Installer: Visit the official WPS Office website and click the free download button.
- 2. Install the Software: Run the setup file and follow the on-screen instructions to install WPS Office on your device.
- 3. Open Your Document: Launch WPS Writer and open your .docx file to seamlessly continue formatting your layouts and cross-references.

Frequently Asked Questions
Why does Word VBA ignore text box captions?
Microsoft Word's internal architecture separates the document into different layers known as 'stories'. The main body text is one story, while shapes and text boxes belong to the shape layer. Standard methods like GetCrossReferenceItems only scan the main document story by default.
What does Run-time Error 4198 mean?
Error 4198 'Command failed' is a generic error in Word VBA indicating that a requested operation cannot be performed in the current context. In this scenario, the macro is trying to process an item index that doesn't exist because the caption wasn't found.
Is there a way to loop through text boxes in VBA?
Yes. Instead of relying on GetCrossReferenceItems, you can write a loop that iterates through ActiveDocument.Shapes or ActiveDocument.StoryRanges(wdTextFrameStory) to identify specific text and programmatically apply references.




