|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
代码供参考。。。- Sub ykcbf() '//2024.3.11
- Set Fso = CreateObject("scripting.filesystemobject")
- Application.ScreenUpdating = False
- Dim tm: tm = Timer
- Set sh = ThisWorkbook.Sheets("查询")
- p = ThisWorkbook.Path & ""
- ReDim brr(1 To 1000, 1 To 6)
- st = Application.InputBox("请输入要查询的字符串:", "字串输入", "防盗锁")
- If st = Empty Then Exit Sub
- On Error Resume Next
- For Each f In Fso.GetFolder(p).Files
- If f.Name Like "*.xls*" Then
- If InStr(f.Name, ThisWorkbook.Name) = 0 Then
- Set wb = Workbooks.Open(f, 0)
- For Each sht In wb.Sheets
- If IsArray(sht.UsedRange) Then
- With sht
- Set Rng = .UsedRange.Find(st)
- If Not Rng Is Nothing Then
- m = m + 1
- brr(m, 1) = m
- brr(m, 2) = Fso.GetBaseName(f)
- brr(m, 3) = .Name
- brr(m, 4) = Replace(Rng.Address, "$", "")
- brr(m, 5) = Rng.Value
- End If
- End With
- End If
- Next
- wb.Close 0
- End If
- End If
- Next f
- With sh
- .UsedRange.Offset(2).Clear
- .[a2].Resize(1, 6).Interior.Color = 49407
- .[e3].Resize(m, 1).Interior.Color = 5296274
- With .[a3].Resize(m, 6)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- .EntireColumn.AutoFit
- End With
- End With
- Application.ScreenUpdating = True
- MsgBox "共用时:" & Format(Timer - tm) & "秒!"
- End Sub
复制代码
|
|