
Originally Posted by
kentnood
Thank you very much, beyond Excel!
This is what I wanted. And yes, I want to create the new destination folders too. Could you advise again, please?
In the attached variant, if the destination path does not exist, the folder is created first, and then the file is copied:
Sub Macro34()
Dim C As Range, Tmp, mPath, iP
For Each C In Range("A2", Range("A1").End(xlDown))
If Right(C(, 2), 1) <> "\" Then C(, 2) = C(, 2) & "\"
If Right(C(, 3), 1) <> "\" Then C(, 3) = C(, 3) & "\"
C(, 4).ClearContents
Select Case True
Case Dir(C(, 2), vbDirectory) = ""
C(, 4) = "Nonexistent Source path"
Case Dir(C(, 2) & C) = ""
C(, 4) = "Nonexistent File"
Case Dir(C(, 3), vbDirectory) = ""
Tmp = Split(C(, 3), "\"): mPath = ""
For Each iP In Tmp
If iP = "" Then Exit For
mPath = mPath & iP & "\"
If Dir(mPath, vbDirectory) = "" Then MkDir mPath
Next
FileCopy C(, 2) & C, C(, 3) & C
C(, 4) = "Successfully transferred"
Case Else
FileCopy C(, 2) & C, C(, 3) & C
C(, 4) = "Successfully transferred"
End Select
Next
End Sub
Bookmarks