Excelmacros根据关键字search文件,并返回true(如果存在)

有人可以帮助我一个Excel VBAmacros来searchB列中提供的各种目录中的文件,根据列A中给出的关键字,并返回列C中的“文件存在”/“文件不存在”。

关键字| FolderPath | 结果

1234 | E:\文档\ ABC

苹果| F:\

File2 | E:\文档\testing\

我是新的Excelmacros。 请帮帮我!

提前致谢!

试试这个:

Sub IsItThere() Dim KeyWd As String Dim Pathh As String, fName As String Dim N As Long, J As Long N = Cells(Rows.Count, "A").End(xlUp).Row For J = 1 To N KeyWd = Cells(J, 1).Value Pathh = Cells(J, 2).Value If Right(Pathh, 1) = "\" Then Pathh = Mid(Pathh, 1, Len(Pathh) - 1) End If Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.Namespace((Pathh)) For Each strFileName In objFolder.Items fName = objFolder.GetDetailsOf(strFileName, 0) If InStr(1, fName, KeyWd) > 0 Then Cells(J, 3).Value = "File Present" GoTo NextRecord End If Next Cells(J, 3).Value = "File Not Present" NextRecord: Set objFolder = Nothing Set objShell = Nothing Next J End Sub