logo
search
VBA & Macro Problems

Fix Word VBA Error 4198: Cross-Referencing Captions in Text Boxes

WPS EditorWPS Editor Oct 10, 2026 869 views

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.

How to Fix Word VBA Error 4198 When Cross-Referencing Text Box Captions
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 you start

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.

Solution 1Recommended

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.

1
Select the target caption

Click inside the text box and highlight the exact text of the caption you want to cross-reference.

2
Insert a custom bookmark

Navigate to the Insert tab on the ribbon, click 'Bookmark', type a unique name without spaces (e.g., 'Fig1Caption'), and click 'Add'.

3
Insert the cross-reference field

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.

4
Update the field

Right-click the field code you just created and select 'Update Field' (or press F9). The caption number or text will now appear.

Manually Bookmark Captions and Insert REF Fields
Macro Automation: If you require this to be fully automated, you will need to write a custom VBA script that iterates through the Shapes collection, identifies the captions, applies bookmarks via code, and then inserts the REF fields.
Free Microsoft Office alternative

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. 1. Download the Installer: Visit the official WPS Office website and click the free download button.
  2. 2. Install the Software: Run the setup file and follow the on-screen instructions to install WPS Office on your device.
  3. 3. Open Your Document: Launch WPS Writer and open your .docx file to seamlessly continue formatting your layouts and cross-references.
Fully compatible with Microsoft Word document formats (.doc, .docx)Intuitive tools for inserting and managing images, frames, and cross-referencesLightweight application that uses minimal system resourcesFree to use with a clean and familiar tabbed user interface
microsoft office alternative - wps office

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.