Document Editing Problems

How to Insert a Dynamic SEQ Number into a Word Table with VBA

Elise WilliamsElise Williams Nov 2, 2026 868 views

Question details

The user needs to insert a dynamic SEQ (sequence) field into a Microsoft Word table using VBA but encounters run-time error 4605 when executing the code.

How to Insert a Dynamic SEQ Number into a Word Table with VBA
Product
Microsoft Word
Device & OS
not provided
Scenario
Automating document formatting by inserting sequential table numbers inside specific table cells using a VBA macro.
Observed behavior
Using the Selection object to add a SEQ field inside a table cell triggers run-time error 4605, and converting the field result to a string permanently breaks the dynamic sequence numbering.
Before you start

Press Alt + F11 to open the Visual Basic for Applications (VBA) editor and locate the specific subroutine where your table generation or formatting code is stored.

Solution 1Recommended

Use the Range Object to Insert the SEQ Field

Avoid run-time error 4605 by manipulating the table cell's Range object directly rather than relying on the cursor's Selection state.

The Selection object behaves unpredictably inside table cells because it often captures the invisible end-of-cell marker. This triggers error 4605 when Word attempts to insert a field over it. By using a precisely defined Range object, you can exclude the marker and ensure the SEQ field is placed correctly while keeping the sequence dynamic.

1
Define the Cell Range

In your VBA code, define a Range object targeting the specific table cell where the sequence number should appear (e.g., `Set myRange = ActiveDocument.Tables(1).Cell(1, 1).Range`).

2
Exclude the End-of-Cell Marker

Move the end of the Range backward by one character using `myRange.MoveEnd Unit:=wdCharacter, Count:=-1` to exclude the hidden cell marker.

3
Collapse the Range

Collapse the Range to the starting insertion point by adding `myRange.Collapse Direction:=wdCollapseEnd`.

4
Insert the Field

Use the Fields.Add method on your defined Range to insert the sequence number: `ActiveDocument.Fields.Add Range:=myRange, Type:=wdFieldEmpty, Text:="SEQ Table \* ARABIC", PreserveFormatting:=True`.

5
Update the Document Fields

Ensure the newly inserted field displays the correct sequence number by running `ActiveDocument.Fields.Update` at the end of your macro.

Use the Range Object to Insert the SEQ Field
Preserving Dynamic Bookmarks: If you are wrapping the inserted field in a bookmark for cross-referencing, do not convert the field's result to a plain string. Leave it as a dynamic Field object so it automatically increments when new tables are added.
Easy Table Numbering in WPS Writer

Insert Dynamic Table Numbers Easily with WPS Office

Avoid complex VBA scripting and run-time errors. WPS Writer offers a straightforward, built-in AutoCaption feature to instantly add and manage dynamic sequence numbers for your tables.

  1. 1. Select Your Table: Open your document in WPS Writer and click on the table you want to number.
  2. 2. Access References: Navigate to the 'References' tab on the top ribbon and click on the 'Caption' button.
  3. 3. Insert the Caption: Choose 'Table' from the Label dropdown menu and select your desired numbering format, then click OK.
  4. 4. Update Dynamically: WPS Writer automatically inserts a dynamic SEQ field. If you move or add tables later, simply right-click the number and select 'Update Field'.
No VBA coding required for dynamic table sequence (SEQ) numbering.Fully compatible with Microsoft Word .docx fields, bookmarks, and captions.Free and lightweight office suite for Windows, Mac, and Linux.
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get run-time error 4605 when inserting a field in a Word table?

This error typically occurs when your VBA macro uses the Selection object inside a table cell and accidentally includes the invisible end-of-cell marker. Using a Range object and explicitly moving the end character back by one resolves this.

How do I keep my SEQ fields dynamic in VBA?

To keep SEQ fields dynamic, ensure you insert them using the Fields.Add method and avoid replacing the field's .Result property with a static string in your code. Always call ActiveDocument.Fields.Update to refresh the sequence values.

Can I cross-reference these dynamically generated table numbers later?

Yes. If you wrap the dynamically inserted SEQ field in a bookmark using your VBA script, you can easily insert cross-reference fields elsewhere in the document that point directly to that specific bookmark.