View Single Post
 
Old 04-13-2021, 03:18 PM
rollis13's Avatar
rollis13 rollis13 is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Jan 2021
Location: Cordenons
Posts: 142
rollis13 will become famous soon enough
Default

You can test if the file to be copied exists, like this:
Code:
Option Explicit
Sub copyfiles()
    Dim m      As Variant
    Dim FileName As String
    Dim FileType As String
    FileType = ".txt"
    For m = 2 To 4
        FileName = Cells(m, 1).Value
        If Dir("C:\Users\roberto.rodriguezram\Desktop\Source\" & FileName & FileType) <> "" Then
            FileCopy "C:\Users\roberto.rodriguezram\Desktop\Source\" & FileName & FileType, _
                     "C:\Users\roberto.rodriguezram\Desktop\Destination\" & FileName & FileType
        End If
    Next
End Sub
Reply With Quote