Dear JBeaucaire,
I have pasted here the code. I get the "Object required" error.
1. I have 3nos files located in E:\0_test search. Each file contains multiple sheets.
2. SearchMultipleFiles.xls contains Sheet1 which contains a string in each of the cells in range A1:A4
3. I wish to sequentially search for each one of these strings (mentioned in item-2 above) in each of the 3nos file located in E:\0_test search.
4. I wish to dump the found strings into SearchMultipleFiles.SearchResults
Sub SearchFolders()
Dim fso As Object
Dim fld As Object
Dim sfl As Object
Dim strSearch As String
Dim strPath As String
Dim strFile As String
Dim wOut As Worksheet
Dim wbk As Workbook
Dim wks As Worksheet
Dim lRow As Long
Dim rFound As Range
Dim strFirstAddress As String
Dim iNoOfRowsInSpreadsheet As Integer
Dim iCellWithTag2Search As Integer
Dim iCellXaminRow As Integer
Dim iCellXaminCol As Integer
Dim wbThis As Workbook
Dim wsTarget As Worksheet
On Error GoTo ErrHandler
Application.ScreenUpdating = False
strPath = "e:\0_test search"
iNoOfRowsInSpreadsheet = 4
iCellXaminRow = 1
iCellXaminCol = 1
Sheets.Add Type:=xlWorksheet
ActiveSheet.Name = "SearchResults"
lRow = 1
Cells(1, 1).Value = "Text in Cell"
Cells(1, 2).Value = "File Name"
Cells(1, 3).Value = "Sheet Name"
Cells(1, 4).Value = "Cell Location"
Worksheets("Sheet1").Select
For iCellXaminRow = 1 To iNoOfRowsInSpreadsheet
strSearch = Cells(iCellXaminRow, iCellXaminCol).Value
With wOut
strFile = Dir(strPath & "\*.xls*")
Do While strFile <> ""
Set wbk = Workbooks.Open _
(FileName:=strPath & "\" & strFile, _
UpdateLinks:=0, _
ReadOnly:=True, _
AddToMRU:=False)
For Each wks In wbk.Worksheets
Set rFound = wks.UsedRange.Find(strSearch)
If Not rFound Is Nothing Then
strFirstAddress = rFound.Address
End If
Do
If rFound Is Nothing Then
Exit Do
Else
Set wbThis = ThisWorkbook
Set wsTarget = wbThis.Worksheets("SearchResults")
wshTarget.Cells(2, 1) = strSearch
End If
Set rFound = wks.Cells.FindNext(After:=rFound)
Loop While strFirstAddress <> rFound.Address
Next
wbk.Close (False)
strFile = Dir
Loop
End With
Next iCellXaminRow
MsgBox "Done!! Now see NEW sheet 'SEARCH RESULTS'"
ExitHandler:
Set wOut = Nothing
Set wks = Nothing
Set wbk = Nothing
Set sfl = Nothing
Set fld = Nothing
Set fso = Nothing
Application.ScreenUpdating = True
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation
Resume ExitHandler
End Sub
Bookmarks