Copy/Rename a file (excel vba)
I currently have an Excel macro that copies a file specified in cell B6 and renames the file using the value in cell D6. Cell B3 and D3 contain the source and destination folder paths. When I run the macro it works great. However, I'd love to be able to copy/rename multiple files based on a cell range (e.g., D6:D100) instead of just one cell (D6). So essentially creating a loop until the last "rename" value is reached within the range of D6:D100. I've provided my current working code below:
-----BEGIN CODE-----
Sub CopyRenameFile()
Dim src As String, dst As String, fl As String
Dim rfl As String
'Source directory
src = Range("B3")
'Destination directory
dst = Range("D3")
'File name
fl = Range("B6")
'Rename file
rfl = Range("D6")
'Debug.Print rfl
On Error Resume Next
FileCopy src & "\" & fl, dst & "\" & rfl
If Err.Number <> 0 Then
MsgBox "Copy error: " & src & "\" & rfl
End If
On Error GoTo 0
End Sub
-----END CODE-----
How should I modify the code to accomplish this?
Recent comments
5 years 34 weeks ago
6 years 20 weeks ago
6 years 32 weeks ago
6 years 35 weeks ago
6 years 36 weeks ago
6 years 42 weeks ago
6 years 50 weeks ago
6 years 50 weeks ago
6 years 50 weeks ago
6 years 50 weeks ago