I have several Word .doc files listed in a listbox and I need to search all of them to see if a certain string of text is found. I don't want any of the documents to be opened, I just want the name(s) of the documents that the text is found in, to be returned to the listbox. It should only show the founded documents in the listbox.
This far have I come with the code, as I think peet wrote. But this code are far away from complete and not okej for my purpose...
VB Code:
  1. Option Explicit
  2. Private objWord As Word.Application
  3. Private wd As Word.Document
  4.  
  5. Private Sub Command1_Click()
  6.    
  7.     If objWord Is Nothing Then
  8.         Set objWord = CreateObject("Word.Application")
  9.     Else
  10.         Set objWord = GetObject(, "Word.Application")
  11.     End If
  12.     DoEvents
  13.     Set wd = objWord.Documents.Open("c:\Test.doc")' Here i want it to get the file from the listbox.
  14.  
  15.     With wd.Content.Find
  16.         .Text = "test"
  17. Wrap:=wdFindContinue
  18.     End With
  19.     objWord.ActiveDocument.Close False
  20.    
  21.     'objWord.Visible = True
  22.     If Not (wd Is Nothing) Then Set wd = Nothing
  23.     If Not (objWord Is Nothing) Then objWord.Application.Quit
  24.     If Not (objWord Is Nothing) Then Set objWord = Nothing
  25.  
  26. End Sub