Thread: [Solved] Search in Range Only Problem
View Single Post
 
Old 10-02-2014, 06:55 AM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,598
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

The behavior is discussed here:
http://gregmaxey.com/word_tip_pages/..._property.html

Basically:
1) we can't find a "thing" when that thing exactly matches the search range, and 2) when that thing does exactly match the search range, the dynamically redefined range is a "runaway" range.

I've modified the PracticalIV code on the page to address your specific issue:

Code:
Sub PracticalIV()
Dim oRng As Word.Range
  'Insert a temporary range modifier.
  Selection.Range.InsertAfter "~"
  Selection.MoveEnd wdCharacter, 1
  Set oRng = Selection.Range
  'Add unique (unanticipated formatting to the modifier).
  oRng.Characters.Last.Font.Bold = False
  With oRng.Find
    .Font.Bold = True
    .Replacement.Text = "<start>^&<end>"
    .Execute Replace:=wdReplaceAll
  End With
  'Delete the modifier.
  oRng.Characters.Last.Delete
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote