Selection.NextField and Selection.PreviousField

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15636
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Selection.NextField and Selection.PreviousField

Post by ChrisGreaves »

The attached Word2003 document contains a plethora of index fields ({XE}) and I am struggling to understand the use of the Selection.NextField method.
I select a chunk of text:-
1.png
... and then run this little macro (present in the document)

Code: Select all

Sub test()
    Dim fldP As Field
    Set fldP = Selection.PreviousField
    Dim fldN As Field
    Set fldN = Selection.NextField
End Sub
... with a break point after each "Set fld" statement.
I never seem to receive a field. My fldP and fldN are always Nothing.
Is it me, or is it something in the water?
You do not have the required permissions to view the files attached to this post.
There's nothing heavier than an empty water bottle

User avatar
HansV
Administrator
Posts: 78524
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Selection.NextField and Selection.PreviousField

Post by HansV »

The problem is that XE fields don't behave like ordinary fields. If you insert fields such as DATE, PAGE etc., the code will work.
Best wishes,
Hans