In a VBA Word macro, I'd like to get a Field
-object for the field which contains the cursor.
The obvious try fails:
Private Sub Try1()
MsgBox Selection.Fields.Count
End Sub
The array is empty. Then I tried:
Private Sub Try2()
Dim oRange As Range
Set oRange = Selection.GoTo(What:=wdGoToField)
MsgBox oRange
End Sub
The cursor does not move, the message is empty.
I can iterate over ActiveDocument.Fields
, compare the ranges and find the containing fiels. But probably there is a simple direct way?
My current production code with iteration over
Document.Fields
: