|
Sub test()
Dim Dic, Wb As Workbook, Ws As Worksheet, Arr, N&, FN$, Str$, Rng As Range
Set Dic = CreateObject("scripting.dictionary")
Str = InputBox("查找内容:", "输入")
If Str = "" Then Exit Sub
Application.ScreenUpdating = False
FN = Dir(ThisWorkbook.Path & "\*.xls*")
Do While FN <> ""
If FN <> ThisWorkbook.Name Then
Set Wb = GetObject(ThisWorkbook.Path & "\" & FN)
With Wb
For Each Ws In .Worksheets
With Ws
Set Rng = .[a1]
If Not .Cells.Find(Str, Rng) Is Nothing Then
Do While .Cells.Find(Str, Rng).Row > Rng.Row Or .Cells.Find(Str, Rng).Column > Rng.Column
Set Rng = .Cells.Find(Str, Rng)
Dic.Add Left(Wb.Name, InStrRev(Wb.Name, ".") - 1) & vbTab & Ws.Name & vbTab & Replace(Rng.Address, "$", "") & vbTab & Rng.Value, ""
Loop
End If
End With
Next Ws
End With
Wb.Close False
End If
FN = Dir
Loop
Set Wb = Nothing
Arr = Dic.keys
With Worksheets("查询")
.Rows("3:" & .Rows.Count).Clear
For N = LBound(Arr) To UBound(Arr)
.Cells(N + 3, 1) = N + 1
.Cells(N + 3, 2).Resize(1, 4) = Split(Arr(N), vbTab)
Next N
.[a3].Resize(N, 6).Borders.LineStyle = 1
End With
Set Dic = Nothing
Application.ScreenUpdating = True
MsgBox "查找完成"
End Sub |
评分
-
1
查看全部评分
-
|