How to Insert a Dynamic SEQ Number into a Word Table with VBA
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.

- 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.
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.
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.
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`).
Move the end of the Range backward by one character using `myRange.MoveEnd Unit:=wdCharacter, Count:=-1` to exclude the hidden cell marker.
Collapse the Range to the starting insertion point by adding `myRange.Collapse Direction:=wdCollapseEnd`.
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`.
Ensure the newly inserted field displays the correct sequence number by running `ActiveDocument.Fields.Update` at the end of your macro.

Utilize Built-in AutoCaption Features
If VBA customization is causing consistent errors, use Word's built-in Caption tool to manage SEQ fields automatically without macros.
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. Select Your Table: Open your document in WPS Writer and click on the table you want to number.
- 2. Access References: Navigate to the 'References' tab on the top ribbon and click on the 'Caption' button.
- 3. Insert the Caption: Choose 'Table' from the Label dropdown menu and select your desired numbering format, then click OK.
- 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'.

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.




