VBA 多个文件批量搜索文字并将结果添加链接

Sub SearchAndRecordResults()
    Dim targetStr As String
    Dim folderPath As String
    Dim fileName As String
    Dim ws As Worksheet
    Dim cell As Range
    Dim resultRow As Long
    
    ' Get the target string to search for 单元格B2检索内容
    targetStr = ThisWorkbook.Sheets("SEARCH").Range("B2").Value
    
    ' Get the folder path 单元格B1路径
    folderPath = ThisWorkbook.Sheets("SEARCH").Range("B1").Value
    
     ' Check if the folder path exists 确认路径是否存在
    If Dir(folderPath, vbDirectory) = "" Then
        MsgBox "Folder path does not exist", vbExclamation
        Exit Sub
    End If
    Dim fileNum
    
    ' Initialize the row number for recording results 第一条结果记录的起始行数
    resultRow = 6
    
    ' Loop through Excel files in the folder 当前文件夹下的所有文件(*.xls*),屏蔽搜索文件本身
    fileName = Dir(folderPath & "\*.xls*")

'对于如何遍历文件目录下的所有子目录请参照下面的方法遍历子文件夹“VBA 调用CMD的tree命令遍历文件”,本文只满足当前文件目录的查找

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值