SEARCHING ALL OPEN .docx

N

number

How can I search through the set of already opened Word 2007 documents
for a string? I want to see each time it occurs where it occurs.
Similar to the "Search all open documents" functionality of Word
2000's Find. thx.
 
G

Graham Mayor

Maybe something like

Sub MarkWord()
Dim oDoc As Document
Dim oRng As Range
Dim sFindText As String
sFindText = InputBox("Find what?")
For Each oDoc In Documents
Set oRng = oDoc.Range
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(findText:=sFindText, _
MatchWholeWord:=True) = True
oRng.HighlightColorIndex = wdTurquoise
Loop
End With
Next oDoc
End Sub

http://www.gmayor.com/installing_macro.htm


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
N

number

You are the man! It works great, the one thing is I need it to take
me to the location of the word in the document where it's found, each
time it's found, then continue to iterate through the open docs.
Thanks!
 
G

Graham Mayor

How about?

Sub MarkWord()
Dim oDoc As Document
Dim oRng As Range
Dim sAsk As String
Dim sFindText As String
sFindText = InputBox("Find what?")
For Each oDoc In Documents
Set oRng = oDoc.Range
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(findText:=sFindText, _
MatchWholeWord:=True) = True
oRng.Select
sAsk = MsgBox("Highlight?", vbYesNo)
If sAsk = vbYes Then
'do what you want with the found item here e.g.
oRng.HighlightColorIndex = wdTurquoise
End If
Loop
End With
Next oDoc
End Sub



You are the man! It works great, the one thing is I need it to take
me to the location of the word in the document where it's found, each
time it's found, then continue to iterate through the open docs.
Thanks!
 
N

number

How about?

Sub MarkWord()
Dim oDoc As Document
Dim oRng As Range
Dim sAsk As String
Dim sFindText As String
sFindText = InputBox("Find what?")
For Each oDoc In Documents
    Set oRng = oDoc.Range
    With oRng.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            Do While .Execute(findText:=sFindText, _
                MatchWholeWord:=True) = True
                oRng.Select
                sAsk = MsgBox("Highlight?", vbYesNo)
                If sAsk = vbYes Then
                    'do what you want with the found item here e.g.
                    oRng.HighlightColorIndex = wdTurquoise
                End If
            Loop
    End With
Next oDoc
End Sub


You are the man!  It works great, the one thing is I need it to take
me to the location of the word in the document where it's found, each
time it's found, then continue to iterate through the open docs.
Thanks!

Correct, yes this works exactly as needed.
 

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

Top