获取指定的文件目录下的指定关键词的文件列表 获取指定文件夹下指定关键词的文件列表(不含子文件夹) 获取指定文件夹下指定关键词的文件列表(含子文件夹) 获取指定文件夹下指定关键词的文件列表(不含子文件夹)——210530更新 获取指定文件夹下指定关键词的文件列表(不含子文件夹) Function aGetFiles(sFolderPath As String, saKey) As Variant '参数:文件夹地址,文件名称关键词(数组) Dim aFiles(), lFilesCount As Long, sFileName As String, sKey as Variant, i As Long For i = LBound(saKey) To UBound(saKey) '将 saKey 中的元素,合并成一个 正则表达式 sKey If i = LBound(saKey) Then sKey = "(" & saKey(i) & ")" Else sKey = sKey & "|(" & saKey(i) & ")" Next i Dim objRegExp As Object, objMatches As Object Set objRegExp = CreateObject("vbscript.regexp") '创建正则对象 With objRegExp .Global = True '多次匹配 .Ignorecase = True '不区分大小写 .MultiLine = True '每行一个行首行尾 .Pattern = sKey '正则表达式 End With If Right(sFolderPath, 1) <> "\" Then sFolderPath = sFolderPath & "\" '如果最后不是 \ ,添加一个 \ sFileName = Dir(sFolderPath & "*.xls*", vbDirectory) '遍历获取后缀名称为 .xls* 的文件 Do While Len(sFileName) <> 0 '只要文件名称不为空就继续循环 If Left(sFileName, 1