Hello, the current code below copies files from the source folder to the destination folder based on cell value and file extension. The files may or may not be used all the time, if the file is not in the source folder I am getting an error. I would like to add code that will skip to the next "phase" if not file is found. Thanks for any help.
Code:
Private Sub CommandButton2_Click()
'copy files into folder
Dim FSO As Object
Dim sourcePath As String
Dim DestinationPath As String
Dim fileExtn As String
'Phase_0
sourcePath = Sheet1.Cells(121, 9).Value
DestinationPath = Sheet1.Cells(110, 13).Value
Sheet1.Cells(115, 4).Value = Sheet1.Cells(100, 4).Value & Sheet1.Cells(110, 4).Value
fileExtn = Sheet1.Cells(115, 4).Value & "*.mpf"
If Right(sourcePath, 1) <> "\" Then
sourcePath = sourcePath & "\"
End If
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.folderExists(sourcePath) = False Then
MsgBox sourcePath & "does not exist"
Exit Sub
End If
If FSO.folderExists(DestinationPath) = False Then
MsgBox DestinationPath & "does not exist"
Exit Sub
End If
FSO.copyfile Source:=sourcePath & fileExtn, Destination:=DestinationPath
'Phase_1
sourcePath = Sheet1.Cells(121, 9).Value
DestinationPath = Sheet1.Cells(111, 13).Value
Sheet1.Cells(116, 4).Value = Sheet1.Cells(100, 4).Value & Sheet1.Cells(111, 4).Value
fileExtn = Sheet1.Cells(116, 4).Value & "*.mpf"
If Right(sourcePath, 1) <> "\" Then
sourcePath = sourcePath & "\"
End If
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.folderExists(sourcePath) = False Then
MsgBox sourcePath & "does not exist"
Exit Sub
End If
If FSO.folderExists(DestinationPath) = False Then
MsgBox DestinationPath & "does not exist"
Exit Sub
End If
FSO.copyfile Source:=sourcePath & fileExtn, Destination:=DestinationPath