Sub 文件夹内查找()
Dim path As String
Dim FileName As String
Dim LastCell As Range
Dim Wkb As Workbook
Dim WS As Worksheet
Dim ThisWB As String
n = 1
sr = InputBox("请输入要查找的内容")
Dim MyDir As String
MyDir = ThisWorkbook.path & "\"
ThisWB = ThisWorkbook.Name
Application.EnableEvents = False
Application.ScreenUpdating = False
path = MyDir
FileName = Dir(path & "\*.xls", vbNormal)
Do Until FileName = ""
If FileName <> ThisWB Then
Set Wkb = Workbooks.Open(FileName:=path & "\" & FileName)
For Each WS In Wkb.Worksheets
Set foundcell = WS.Cells.Find(sr, LookAt:=xlWhole)
If Not foundcell Is Nothing Then
With ThisWorkbook.Sheets(1)
.[A1:C1] = Array("单元格地址", "工作表名", "工作簿名")
n = n + 1
.Cells(n, 1) = foundcell.Address(0, 0)
.Cells(n, 2) = WS.Name
.Cells(n, 3) = Wkb.Name
End With
End If
Next WS
Wkb.Close False
End If
FileName = Dir()
Loop
Application.EnableEvents = True
Application.ScreenUpdating = True
Set Wkb = Nothing
End Sub
追问你好 这个文件可以啊 。只是当同一个表中 关键词次出现时 ,能否全都搜索出来。能否帮我完善一下?
追答