Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Marshall Abrams
 
Posts: n/a
Default Sears two words near each other

Is there a way to search a Word document for word1 near word2? It would be
nice to be able to specify what "near"means (e.g., same sentnece, same
paragraph, within n words).
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Doug Robbins - Word MVP
 
Posts: n/a
Default Sears two words near each other

The following macro will find and select the text beginning and ending with
the words that it asks for if they are in the same paragraph. I could be
modified for the other cases that you mention.

Dim myrange As Range
Dim firstword As String
Dim secondword As String
Dim i As Long
firstword = InputBox("Enter the first word that you want to find")
secondword = InputBox("Enter the second word that you want to find")
i = Len(secondword)
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:=firstword, MatchWildcards:=False,
Wrap:=wdFindStop, Forward:=True) = True
Set myrange = Selection.Range
myrange.End = Selection.Paragraphs(1).Range.End
If InStr(myrange, secondword) 1 Then
myrange.End = myrange.Start + InStr(myrange, secondword) + i - 1
myrange.Select
Exit Do
Else
Selection.Collapse wdCollapseEnd
End If
Loop
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Marshall Abrams" wrote in
message ...
Is there a way to search a Word document for word1 near word2? It would be
nice to be able to specify what "near"means (e.g., same sentnece, same
paragraph, within n words).



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word should catalog misspelled words to study. rndthought Microsoft Word Help 39 May 21st 23 02:47 AM
How to find a series of words and then changing formats MolTom Microsoft Word Help 4 December 13th 05 03:05 PM
In Word, word usage Cheri Microsoft Word Help 2 December 6th 05 09:44 PM
How can I find if there are doubles in my list of words? Rhen Microsoft Word Help 3 June 9th 05 05:12 AM
How many times are words used in a document. Marker Microsoft Word Help 4 March 9th 05 04:55 AM


All times are GMT +1. The time now is 04:01 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"