Hi
In this macro copy file & rename and paste that to particular folder but i want update status in Column D file is already exits or able to save that file then Done please tell me how to do this
In this macro copy file & rename and paste that to particular folder but i want update status in Column D file is already exits or able to save that file then Done please tell me how to do this
Code:
Function file_exists(fl_path As String) As String
If Dir(fl_path) <> "" And fl_path <> "" Then
file_exists = "Exists"
Else
file_exists = "Not Exists"
End If
End Function
Sub CopyRenameFile()
Dim src As String, dst As String, fl As String
Dim rfl As String
Dim i As Long, LRow As Long
LRow = ActiveSheet.Range("E" & Rows.Count).End(xlUp).Row
For i = 2 To LRow
'Source directory
src = Range("B2")
'Destination directory
dst = Range("C2")
'File name
fl = Range("A2")
'Rename file
rfl = Range("E" & i)
If file_exists(dst) = "Exists" Then
MsgBox "File already exists at destination folder so can not be moved ", vbInformation, "Note:"
Exit Sub
End If
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
Next i
End Sub