Hello Everyone,
This is my first post. I'm rather novice at VBA, but I found a post elsewhere that had some code to copy and rename files. I would like to utilize this code, but I need to be able to copy and rename a range of cells, and the code posted was only for one cell. Can anyone suggest how to either loop this VBA code or modify it for a range?
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")
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
Thanks in advance.
This is my first post. I'm rather novice at VBA, but I found a post elsewhere that had some code to copy and rename files. I would like to utilize this code, but I need to be able to copy and rename a range of cells, and the code posted was only for one cell. Can anyone suggest how to either loop this VBA code or modify it for a range?
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")
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
Thanks in advance.