Hi Iggitha,
Bear's suggestions might be preferred.
If you want to learn it the hard way,
then here we go.
Starting from a new, blank document:
Sub Test()90067
Dim strDir As String ' a folder
Dim strDoc As String ' a document
Dim strKey As String ' a keyword
Dim DcmTmp As Document ' the doc which is searched for a keyword
Dim DcmPrm As Document ' the permanent doc to collect the results
Set DcmPrm = ActiveDocument
' make sure it is empty !
strKey = InputBox("keyword to search for")
strDir = "c:\test\word1\" ' fixed folder !
strDoc = Dir(strDir & "*.doc")
While strDoc <> ""
Set DcmTmp = Documents.Open(strDir & strDoc)
With DcmTmp.Range.Find
.Text = strKey
If .Execute Then
DcmPrm.Range.InsertAfter _
strKey & " was found in " & DcmTmp.FullName & vbCrLf
End If
End With
DcmTmp.Close
strDoc = Dir()
Wend
End Sub
There is a lot of flickering on the screen, despite of
Application.ScreenUpdating = False
But doesn't matter here, I think.
Note that this searches the document's main story.
Searching *all* of the doc, headers end footers,
text boxes, captions, whatsoever,
would be a quite different story.
--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Vista Small Business, Office XP