Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

search result in a range

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew V - 25 Nov 2006 07:05 GMT
I'm wondering about the use of myRange.Find as opposed to Selection.Find.  Is
there some way I can use the former and return/determine the range of its
result?  Selection.Find highlights (selects) the result, but I can find no
equivalent action for myRange.Find.

Thanks,
Andrew
Jean-Guy Marcil - 25 Nov 2006 07:27 GMT
Andrew V  was telling us:
Andrew V nous racontait que :

> I'm wondering about the use of myRange.Find as opposed to
> Selection.Find.  Is there some way I can use the former and
> return/determine the range of its result?  Selection.Find highlights
> (selects) the result, but I can find no equivalent action for
> myRange.Find.

Try something like this:

'_______________________________________
Sub SelectRangeFind()

Dim myRange As Range

Set myRange = ActiveDocument.Range

With myRange.Find
   .Text = "Some text"
   .Execute
   If .Found Then
       With .Parent
           .Select
       End With
   End If
End With

End Sub
'_______________________________________

In fact, .Parent refers to the found range.

So you can put anything you would normally do with a range between the
       With .Parent

       End With

as in:

       With .Parent
           .Bold = True
           .Font.Name = "Arial"
           .Characters(1).Font.Color = wdColorBlue
       End With

You do not even have to select the found result.
And you can use a loop to apply those changes to all found items:

'_______________________________________
Sub SelectRangeFind()

Dim myRange As Range

Set myRange = ActiveDocument.Range

With myRange.Find
   .Text = "Some text"
   Do While .Execute
       With .Parent
           .Bold = True
           .Font.Name = "Arial"
           .Characters(1).Font.Color = wdColorBlue
       End With
   Loop
End With

End Sub
'_______________________________________

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Andrew V - 25 Nov 2006 17:49 GMT
That's precisely what I was looking for.  Thanks a million!

Andrew

> Andrew V  was telling us:
> Andrew V nous racontait que :
[quoted text clipped - 65 lines]
> End Sub
> '_______________________________________
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.