|
- Sub 搜索() 'by: bajifeng
- Dim brr()
- pn = [b3].Value
- [c3:e10] = ""
- fn = GetFilesList(ThisWorkbook.Path) 'ThisWorkbook.Path是当前代码文件所在路径,路径名可以根据需求修改
- Application.ScreenUpdating = False
- For l = 0 To UBound(fn)
- Workbooks.Open fn(l)
- For Each Sht In Worksheets
- m = m + 1
- n = n + 1
- Sheets(n).Activate
- lr = [a65536].End(3).Row
- arr = Range("a3:a" & lr).Value
- ReDim Preserve brr(1 To 3, 1 To n)
- For i = 1 To UBound(arr)
- If arr(i, 1) = pn Then
- brr(1, n) = Replace(Split(fn(l), "")(UBound(Split(fn(l), ""))), ".xls", "")
- brr(2, n) = Sht.Name
- brr(3, n) = CStr(i + 2)
- brr(3, n) = "A" & brr(3, n)
- ActiveWorkbook.Close
- GoTo 100
- End If
- Next
- Next
- ActiveWorkbook.Close
- n = 0
- Next
- 100:
- [c3].Resize(1, 3) = Application.Transpose(brr)
- Application.ScreenUpdating = True
- MsgBox "处理完毕!"
- End Sub
- Function GetFilesList(sPath$) As Variant 'bajifeng
- Dim arr()
- Set fso = CreateObject("scripting.filesystemobject")
- Set ff = fso.getfolder(sPath)
- For Each f In ff.Files
- If Not InStr(f.Name, ThisWorkbook.Name) > 0 Then
- ReDim Preserve arr(n)
- arr(n) = f
- n = n + 1
- End If
- Next
- GetFilesList = arr
- End Function
复制代码 |
|