miguel78
12-16-2016, 08:57 AM
Hello,
I need some help to adjust this code found on the internet.
I would like that whenever I run the code, new files on the destination folder are never overwritten. The solution seems easy, but I tried a lot and I'm inexperienced in VBA. Please help me.
File attached.
Thank you.
Sub gerafiles()
Dim src As String, dst As String, fl As String
Dim rfl As String
Dim lngMyRow As Long
Dim lngLastRow As Long
Application.ScreenUpdating = True
lngLastRow = Range("B:D").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
'Source directory
src = Range("B3")
'Destination directory
dst = Range("D3")
For lngMyRow = 6 To lngLastRow
'File name
fl = Range("B" & lngMyRow)
'Rename file
rfl = Range("D" & lngMyRow)
On Error Resume Next
FileCopy src & "\" & fl, dst & "\" & rfl
On Error GoTo 0
Next lngMyRow
Application.ScreenUpdating = True
MsgBox "OK"
End Sub17844
I need some help to adjust this code found on the internet.
I would like that whenever I run the code, new files on the destination folder are never overwritten. The solution seems easy, but I tried a lot and I'm inexperienced in VBA. Please help me.
File attached.
Thank you.
Sub gerafiles()
Dim src As String, dst As String, fl As String
Dim rfl As String
Dim lngMyRow As Long
Dim lngLastRow As Long
Application.ScreenUpdating = True
lngLastRow = Range("B:D").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
'Source directory
src = Range("B3")
'Destination directory
dst = Range("D3")
For lngMyRow = 6 To lngLastRow
'File name
fl = Range("B" & lngMyRow)
'Rename file
rfl = Range("D" & lngMyRow)
On Error Resume Next
FileCopy src & "\" & fl, dst & "\" & rfl
On Error GoTo 0
Next lngMyRow
Application.ScreenUpdating = True
MsgBox "OK"
End Sub17844