|
Sub test()
Dim Dic, Wb As Workbook, Ws As Worksheet, Arr, N&, FN$, Str$, Rng As Range, Str2$
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
If WorksheetFunction.CountIf(.UsedRange, "*" & Str & "*") <> 0 Then
Set Rng = .UsedRange.Find(Str)
Do
Str2 = Left(Wb.Name, InStrRev(Wb.Name, ".") - 1) & vbTab & Ws.Name & vbTab & Replace(Rng.Address, "$", "") & vbTab & Rng.Value & vbTab & Rng.Offset(0, 2).Value
If Not Dic.exists(Str2) Then Dic.Add Str2, ""
Set Rng = .UsedRange.Find(Str, Rng)
Loop While .UsedRange.Find(Str).Address <> Rng.Address
End If
End With
Next Ws
End With
Wb.Close False
End If
FN = Dir
Loop
Set Wb = Nothing
With Worksheets("查询")
.Rows("3:" & .Rows.Count).Clear
If Dic.Count > 0 Then
Arr = Dic.keys
For N = LBound(Arr) To UBound(Arr)
.Cells(N + 3, 1) = N + 1
.Cells(N + 3, 2).Resize(1, 5) = Split(Arr(N), vbTab)
Next N
.[a3].Resize(N, 6).Borders.LineStyle = 1
MsgBox "查找完成"
else
msgbox "不存在你要搜索的内容"
End If
End With
Set Dic = Nothing
Application.ScreenUpdating = True
End Sub
[ 本帖最后由 kevinchengcw 于 2010-10-30 20:08 编辑 ] |
|