Try the code below. Provide the string to find and folder name:
Sub StringSearch()
Dim wb As Object
Dim strText As String
strText = "............." 'string to find
With Application.FileSearch
.NewSearch
.LookIn = "C:\........" 'folder name
.SearchSubFolders = True
.FileType = msoFileTypeExcelWorkbooks
End With
With Application.FileSearch
If .Execute() 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
Application.DisplayAlerts = False
For i = 1 To .FoundFiles.Count
Set wb = Workbooks.Open(Filename:=.FoundFiles(i))
If FindString(strText, wb) = True Then
MsgBox "Found " & strText & " in "
.FoundFiles(i)
End If
wb.Close
Set wb = Nothing
Next i
Application.DisplayAlerts = True
Else
MsgBox "There were no files found."
End If
End With
End Sub
Function FindString(strText, wb) As Boolean
Dim i As Integer
Dim z As Long
'The following example uses the Find method to verify that the
'specified block of lines, lines 1261 through 1279,
'of a particular code pane does contain the string "Tabs.Clear."
'.....CodeModule.Find (text to find, start line, start position
end line, end line position, False, False)
On Error GoTo FindError
For i = 1 To Application.VBE.VBProjects.Count
If InStr(1, Application.VBE.VBProjects(i).Filename, wb.Name)
0 Then
For m = 1 T
Application.VBE.VBProjects(i).VBComponents.Count
With Application.VBE.VBProjects(i).VBComponents(m)
If .CodeModule.Find(strText, z, 1, z + 1, 1, False
False) Then
FindString = True
Exit Function
End If
End With
Next m
End If
Next i
Exit Function
FindError:
If Err.Number = 50289 Then 'file is password protected
MsgBox wb.Name & " is protected and cannot be scanned
Continuing.."
FindString = False
Exit Function
End If
End Functio
--
Message posted from
http://www.ExcelForum.com