|
有一段代码。复制到指定文件夹123,但是这个文件夹只能在同一个目录下吗?可以改成其他的路径吗?比如 C:/123/
Public arr
Public str1
Sub 按钮2_Click()
arr = Range("d2:d" & Cells(Rows.Count, "d").End(3).Row + 1)
Application.ScreenUpdating = False
str1 = ThisWorkbook.Path & "123"
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, "123") = 0 Then
For Each f In ff.Files
For k = 1 To UBound(arr)
If InStr(f.Name, arr(k, 1)) > 0 And Len(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
|
|