searching for proximate terms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

It would be very halpful if one could search Word documents for a word or
phrase that is within a certain proximity of another word or phrase. I
realize there is a feature that allows one to check 'Use wildcards' that in
principle should be able to do this, but my experience has been that it just
doesn't work properly.
Thanks,
Bob

----------------
This post is a suggestion for Microsoft, and Microsoft responds to the
suggestions with the most votes. To vote for this suggestion, click the "I
Agree" button in the message pane. If you do not see the button, follow this
link to open the suggestion in the Microsoft Web-based Newsreader and then
click "I Agree" in the message pane.

http://www.microsoft.com/office/com...53fe30&dg=microsoft.public.word.docmanagement
 
Robert,

The following code is just a basic attempt at automating something like
you are looking for. I did not polish the cannonball here:

Say you wanted to find out if one word "fox" was within 5 or less words
from another word "dog." Here is our text:

Blah, blah, blah,

The quick red fox jumped over the lazy brown dog.

Sub ScratchMacro()
Dim oRng1 As Word.Range
Dim oRng2 As Word.Range
Dim oSpanRng As Word.Range
Set oRng1 = ActiveDocument.Range
Set oRng2 = ActiveDocument.Range
With oRng1.Find
.Text = "fox"
.Execute
oRng1.Select
Set oSpanRng = oRng1
oSpanRng.Start = oRng1.End
End With
With oRng2.Find
.Text = "dog"
.Execute
oRng2.Select
oSpanRng.End = oRng2.Start
End With
oSpanRng.Select
If DlgWordCount < 6 Then MsgBox "Found"
End Sub
Private Function DlgWordCount() As Long
Dim dlg As Dialog
Set dlg = Dialogs(wdDialogToolsWordCount)
dlg.Execute
DlgWordCount = dlg.Words
Set dlg = Nothing
End Function
 
Robert,

Thanks for the e-mail. I my haste I deleted it before taking the time to
respond. Sorry.

I have experimented with the idea a bit further. Consider the following:

Text
The quick red fox jumps over the lazy brown dog.
Blah, blah,
The red fox jumps over the dog.
The fox jumps over the the lazy, dirty, brown dog.
End Text

Running this macro will alert you on line one and two but not line three.

Sub ScratchMacro()
Dim oRng1 As Word.Range
Dim oRng2 As Word.Range
Dim oSpanRng As Word.Range
Dim bFF As Boolean
Dim bFS As Boolean
Set oRng1 = ActiveDocument.Range
Set oRng2 = ActiveDocument.Range
Do
With oRng1.Find
.Text = "fox"
.Execute
If .Found Then
Set oSpanRng = oRng1.Duplicate
oSpanRng.Start = oRng1.End
oRng1.Collapse wdCollapseEnd
bFF = True
Else
Exit Do
End If
End With
With oRng2.Find
.Text = "dog"
.Execute
If .Found Then
oSpanRng.End = oRng2.Start
oRng2.Collapse wdCollapseEnd
bFS = True
Else
Exit Do
End If
End With
If bFF = True And bFS = True Then
oSpanRng.Select
If DlgWordCount < 6 Then MsgBox "Instance Found"
End If
bFS = False
bFS = False
Loop
Selection.Collapse wdCollapseEnd
End Sub
Private Function DlgWordCount() As Long
Dim dlg As Dialog
Set dlg = Dialogs(wdDialogToolsWordCount)
dlg.Execute
DlgWordCount = dlg.Words
Set dlg = Nothing
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top