Re: Need selection to include a field
From: Peter Hewett (nospam_at_xtra.co.nz)
Date: 06/12/04
- Next message: Peter Jamieson: "Re: How to run word and pass a mail merge values and fax it to the recipient"
- Previous message: David Thielen: "Need selection to include a field"
- In reply to: David Thielen: "Need selection to include a field"
- Next in thread: David Thielen: "Re: Need selection to include a field"
- Reply: David Thielen: "Re: Need selection to include a field"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 12 Jun 2004 21:05:35 +1200
Hi David Thielen
Try the following code it will tell you if the selection is within, contains or is
immediately adjacent (cause the field shading to show) to a field:
Public Function SelectionContainsAField() As Boolean
Dim rngAdjacent As Word.Range
Dim rngParagraph As Word.Range
Dim fldItem As Word.Field
' If the insertion point is in a field the field count
' is zero. This code allows for that problem.
' No more to do if the selected range contains a field
If Selection.Fields.Count > 0 Then
SelectionContainsAField = True
Exit Function
End If
' Copy the current selection into range objects
' so that we don't change the selection
Set rngParagraph = Selection.Range
Set rngAdjacent = Selection.Range
' Extend range to include current paragraph, if Selection is
' in a field the range is expanded to include that field
rngParagraph.Expand wdParagraph
For Each fldItem In rngParagraph.Fields
' If the selection is an insertion point adjacent to
' the field, then that also constitutes a match.
If Selection.Type = wdSelectionIP Then
If rngAdjacent.Start = fldItem.Code.Start - 1 Then
SelectionContainsAField = True
Exit For
End If
End If
' Make sure IP is really in a field and it's not just
' the expanded paragraph that picked up a field
If Selection.InRange(fldItem.Result) Then
SelectionContainsAField = True
Exit For
End If
Next
End Function
HTH + Cheers - Peter
David Thielen <david@windward.net>, said:
>Hi;
>
>When the caret is on a field, the selection is for the text char just
>before the field. How can I find out if a selection is on a field?
>
>thanks - dave
- Next message: Peter Jamieson: "Re: How to run word and pass a mail merge values and fax it to the recipient"
- Previous message: David Thielen: "Need selection to include a field"
- In reply to: David Thielen: "Need selection to include a field"
- Next in thread: David Thielen: "Re: Need selection to include a field"
- Reply: David Thielen: "Re: Need selection to include a field"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|