3

I would like to ask your help with the following issue:

I have created a specification template in MS Word with a feature to insert a drop-down list into a table. The list is filled up automatically with the bibliography of the specification (name of the documents + paths to the storage locations). After the user selected the proper document from the list (and clicked to somewhere else), my script will insert a link into another cell of the table, so the user can easily open the referenced document.

This function was working perfectly for a while (more than a year), however if I try to use it now, it seems it gets stuck in an infinite loop after the link is inserted. The cursor should be dropped to the position the user clicked after choosing the document, but instead, the cursor is dropped to the start position of the cell of the link and the range of the cell is selected over and over again. If I put at least 1 break point anywhere into the script and let it run step-by-step, the function works correctly, however if I try to let it run without break points, the function will get stuck.

The code was not modified, however my system was upgraded Win10 -> Win11 and probably some Office updates.

Code of the event handler:

Private Sub Document_ContentControlOnExit(ByVal dropDown As contentcontrol, Cancel As Boolean)
 Dim myTable As Table
 Dim rowID As Long
 Dim index As Integer
 Dim content As String
 
 If InStr(dropDown.Tag, "procedureDropDown") > 0 Then
 dropDown.Range.Select
 Set myTable = Selection.Tables(1)
 rowID = Selection.Cells(1).RowIndex
 
 For index = 1 To dropDown.DropdownListEntries.Count
 If dropDown.DropdownListEntries(index).Text = dropDown.Range.Text Then
 myTable.Cell(rowID, myTable.Columns.Count - 3).Select
 Selection.Text = "Link to the procedure"
 
 ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, address:=dropDown.DropdownListEntries(index).Value
 Exit Sub
 
 End If
 Next index
 
 End If
End Sub

Cursor tracker:

Option Explicit
Public WithEvents positionTracker As Word.Application
Public currentPosition As Range
Public previousPosition As Range
Private Sub positionTracker_WindowSelectionChange(ByVal newSelection As Selection)
 If Not currentPosition Is Nothing Then
 Set previousPosition = currentPosition
 End If
 
 Set currentPosition = newSelection.Range
End Sub

Do you have any idea what could have happened and how can it be solved?

GSerg
78.9k18 gold badges173 silver badges377 bronze badges
asked Dec 15, 2025 at 15:53
2
  • Does it help if you protect from reentrancy? Commented Dec 15, 2025 at 16:22
  • Yes, that solved it + position changes are eliminated from the code. Commented Dec 16, 2025 at 9:54

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.