现在有个文件夹,下面有20个子文件夹,每个子文件夹中有10个文件,现在想做个程序,在整个文件夹(包括文件夹)中搜索文件名包含指定字符(比如包含“A”字符)的文件,并把找到的文件拷贝到指定目录,应该怎么做呢? Sub 复制2() '包含子文件夹 Dim MyPath As String On Error Resume Next MyPath = Range("c2") & "\" copyFiles MyPath End Sub Function copyFiles(fpath As String) Dim Folder As Object Dim Fld As Object Set fso = CreateObject("Scripting.FileSystemObject") Set Fld = fso.GetFolder(fpath) For i = 2 To Range("a56564").End(3).Row fso.copyfile fpath & "\*" & Cells(i, 1) & "*.*", ThisWorkbook.Path & "\02" Next i For Each Folder In Fld.SubFolders copyFiles = copyFiles(Folder.Path) '递归遍历子文件夹 Next Set fso = Nothing End Function |
|
来自: 昵称QAb6ICvc > 《vba应用》