|

楼主 |
发表于 2014-12-17 00:05
|
显示全部楼层
应用扩展一
遍历当前文件夹及子文件夹,查找包含指定字符串的文件名并执拷贝到指定文件夹
将文件名包含D列字符串的的 拷贝到“合并文件夹”里
Public arr
Public str1
Sub 按钮2_Click()
arr = Range("d2:d" & Cells(Rows.Count, "d").End(3).Row)
Application.ScreenUpdating = False
str1 = ThisWorkbook.Path & "\合并文件夹\"
Getfd (ThisWorkbook.Path)
Application.ScreenUpdating = True
End Sub
Sub Getfd(ByVal pth)
Set fso = CreateObject("scripting.filesystemobject")
Set ff = fso.getfolder(pth)
If InStr(ff, "合并文件夹") = 0 Then
For Each f In ff.Files
For k = 1 To UBound(arr)
If InStr(f.Name, arr(k, 1)) > 0 Then
fso.CopyFile f, str1, True '拷贝并覆盖
' fso.moveFile f, str1 '拷贝并覆盖
' fso.DeleteFile f, True '忽略文件只读属性,直接删除
Exit For
End If
Next k
Next f
End If
For Each fd In ff.subfolders
Getfd (fd)
Next fd
End Sub
补充内容 (2015-2-6 07:38):
仅有一个条件的时候,考虑不周,已经在36楼更新
http://club.excelhome.net/forum. ... 866&pid=8083857 |
评分
-
4
查看全部评分
-
|