Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Word should catalog misspelled words to study. | Microsoft Word Help | |||
How to find a series of words and then changing formats | Microsoft Word Help | |||
In Word, word usage | Microsoft Word Help | |||
How can I find if there are doubles in my list of words? | Microsoft Word Help | |||
How many times are words used in a document. | Microsoft Word Help |