![]() |
|
#2
|
||||
|
||||
|
What you really need to do here is to determine whether the selection is within a field. The following function does that.
Code:
Function WithInField(Rng As Word.Range) As Boolean ' Based on code by Don Wells: http://www.eileenslounge.com/viewtopic.php?f=30&t=6622 ' Approach : This procedure is based on the observation that, irrespective of _ a field's ShowCodes state, toggling the field's ShowCodes state _ twice collapses the selection to the start of the field. Dim lngPosStart As Long, lngPosEnd As Long, StrNot As String WithInField = True Rng.Select lngPosStart = Selection.Start lngPosEnd = Selection.End With Selection .Fields.ToggleShowCodes .Fields.ToggleShowCodes ' Test whether the selection has moved; if not, it may already have been _ at the start of a field, in which case, move right and test again. If .Start = lngPosStart Then .MoveRight .Fields.ToggleShowCodes .Fields.ToggleShowCodes If .Start = lngPosStart + 1 Then WithInField = False End If End If End With End Function Code:
Sub TestWithInField()
Dim Rng As Word.Range, c As Word.Range, StrRslt As String
Set Rng = Selection.Range
For Each c In Rng.Characters
StrRslt = StrRslt & c.Text & ",WithInField:" & WithInField(Rng:=c) & vbCr
Next
Rng.Select
MsgBox StrRslt
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Selection or Range | Tommes93 | Word VBA | 1 | 04-10-2014 02:50 AM |
Selection of all Text for a specific page in word is spanning selection across pages
|
ramsgarla | Word VBA | 9 | 12-05-2012 03:23 AM |
Word VBA: Cannot Edit Range (Delete characters except the first in a table cell)
|
tinfanide | Word VBA | 3 | 04-27-2012 09:48 AM |
Set range for merged Word table cells?
|
tinfanide | Word VBA | 1 | 02-06-2012 05:57 AM |
you cannot insert this selection into a table.
|
cs_starter | Mail Merge | 2 | 09-08-2011 02:58 AM |