EXCEL.XLS中快速查找关键词VBA.rar

上传者: topmangang | 上传时间: 2021-07-09 22:08:43 | 文件大小: 22KB | 文件类型: RAR
Option Explicit Private Sub CommandButton1_Click() Dim ar, br(), i&, j&, k&, m&, myFile$, myPath$, myStr$, Rng As Range, Wb, Ws, tms# Application.ScreenUpdating = False On Error Resume Next If Range("n3") = "" Then MsgBox "N列中没有要查询的内容": Exit Sub m = Range("n2").End(4).Row - 1 ar = Range("n2").Resize(m) ReDim br(65530, 5) With Application.FileDialog(msoFileDialogFolderPicker) If .Show Then myPath = .SelectedItems(1) Else myPath = ThisWorkbook.Path End With If Right(myPath, 1) "\" Then myPath = myPath & "\" tms = Timer myFile = Dir(myPath & "*.xls*") Do While myFile "" If myFile ThisWorkbook.Name Then br(k, 1) = Left(myFile, InStrRev(myFile, ".") - 1) Set Wb = GetObject(ThisWorkbook.Path & "\" & myFile) With Wb '利用GetObject在后台打开工作簿 For Each Ws In .Worksheets '循环当前工作簿中每个工作表 br(k, 2) = Ws.Name With Ws For i = 2 To m myStr = ar(i, 1) If WorksheetFunction.CountIf(.UsedRange, "*" & myStr & "*") 0 Then Set Rng = .UsedRange.Find(myStr) Do br(k, 3) = Rng.Address(0, 0) br(k, 4) = Rng.Text br(k, 5) = myStr br(k, 0) = k + 1 k = k + 1 br(k, 1) = br(k - 1, 1) br(k, 2) = br(k - 1, 2) Set Rng = .UsedRange.Find(myStr, Rng) Loop While .UsedRange.Find(myStr).Address Rng.Address End If Next End With Next Ws .Close False '不保存关闭工作簿 End With End If myFile = Dir Loop Set Wb = Nothing Range("a1").CurrentRegion.Offset(2) = "" myStr = "很遗憾、不存在你要搜索的内容。" If k Then Range("a3").Resize(k, 6) = br Range("a3").Resize(k, 6).Borders.LineStyle = 1 以下还有内容……见附件!

文件下载

资源详情

[{"title":"( 1 个子文件 22KB ) EXCEL.XLS中快速查找关键词VBA.rar","children":[{"title":"查找关键词.xls <span style='color:#111;'> 56.00KB </span>","children":null,"spread":false}],"spread":true}]

评论信息

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明