Thread: [Solved] Search in Range Only Problem
View Single Post
 
Old 10-02-2014, 07:05 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

NP,

No the problem is universal. Again it is a result of trying to find something in a range when the range is that something. Here is another demo:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range
  ActiveDocument.Range.Delete
  ActiveDocument.Range.Text = "Test"
  Set oRng = ActiveDocument.Words(1)
  Debug.Print oRng
  With oRng.Find
    .Text = "Test"
    If .Execute Then
      MsgBox "Found"
    Else
      MsgBox "Not found.  Why? Because the thing we are looking for exactly matches the search range." & _
             " We can't find ""Test"" IN the search range because ""Test"" IS the search range."
    End If
  End With
  'Now redefine the range.
  Set oRng = ActiveDocument.Range '(includes Words(1) and the end of document mark.
  Debug.Print oRng
  With oRng.Find
    .Text = "Test"
    If .Execute Then
      MsgBox "Found."
    End If
  End With
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote