Excel 2003 - Launch a text search of a directory

Con risposta Excel 2003 - Launch a text search of a directory

  • mercoledì 8 settembre 2010 09:17
     
     

    Hello All,

    I would like to allow users of a workbook to launch a search of a directory of files to seek particular text. Perferably, I would like them to select the text in the workbook and then have this carried to the search as a parameter, but just opening  a text search window would be a good start.

    Also, the directory of the search will be known, so I would like to avoid the user having to find it.

    Any suggestions?

     

    Thanks

    NorthernRoyal

Tutte le risposte

  • venerdì 10 settembre 2010 14:47
     
     Con risposta

    Take a look at Application.FileSearch in Excel VBA help.

    Something like this:

    Sub look()
      Dim F
      With Application.FileSearch
        .NewSearch
        .FileType = msoFileTypeAllFiles
        .LookIn = "C:\Temp"
        .TextOrProperty = "Manville"
        .Execute
        If .FoundFiles.Count = 0 Then
          MsgBox "No such files found"
        Else
          For Each F In .FoundFiles
            MsgBox F & " contains the text you are looking for"
          Next
        End If
      End With
    End Sub

     


    Bill Manville. Excel MVP, Oxford, England. www.manville.org.uk