|
这是一个大佬帮写的代码:根据escel内的A列的目录从A文件夹移动指定的文件夹到B文件夹,想要把移动变成复制,有没有老板帮帮忙,在这个代码上改一改,谢谢
Sub 移动文件()
Dim nRow%, Arr(), nFg%
Dim cPath$, cPath2$, cFile$, cFile2$
Dim Fso As Object
Set Fso = CreateObject("Scripting.FileSystemObject")
cPath = ThisWorkbook.Path & "\源文件\"
cPath2 = ThisWorkbook.Path & "\目标文件\"
nRow = Range("a1048576").End(xlUp).Row
Arr = Range("a1:a" & nRow).Value
For i = 2 To nRow
cFile = Dir(cPath & "*" & Arr(i, 1) & "*", 16)
If Len(cFile) > 2 And GetAttr(cPath & cFile) = 16 Then
cFile2 = Dir(cPath2 & "*" & Arr(i, 1) & "*", 16)
If cFile = cFile2 Then
If nFg <> 6 Then
nFg = MsgBox("目标文件夹中存在同名文件,是否覆盖? " & vbCrLf _
& "是—— 全部覆盖,不再提示" & vbCrLf _
& "否—— 覆盖当前文件《" & cFile2 & "》" & vbCrLf _
& "取消— 不移动该文件", 35, "覆盖确认")
End If
If nFg > 2 Then Fso.DeleteFolder cPath2 & cFile2
End If
If nFg = 2 Then
nFg = 0
Else
Fso.MoveFolder cPath & cFile, cPath2 & cFile
End If
End If
Next
End Sub
|
|