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?
-
Does it help if you protect from reentrancy?GSerg– GSerg2025年12月15日 16:22:53 +00:00Commented Dec 15, 2025 at 16:22
-
Yes, that solved it + position changes are eliminated from the code.user32055254– user320552542025年12月16日 09:54:36 +00:00Commented Dec 16, 2025 at 9:54