I have the following code to move all of my csv files from one folder to another.
However, I now need to be more specific.
Could anybody edit my code or illustrate how how I would move four specific files. e.g.
FileOne.csv
FileTwo.csv
FileThree.csv
FileFour.csv
Many thanks in advance.
However, I now need to be more specific.
Could anybody edit my code or illustrate how how I would move four specific files. e.g.
FileOne.csv
FileTwo.csv
FileThree.csv
FileFour.csv
Many thanks in advance.
Code:
Private Sub Command0_Click()
On Error GoTo Handler
'Note: If the files in ToPath already exist it will overwrite
'existing files in this folder
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
FromPath = "H:\Downloads"
ToPath = "S:\DATA_FILES\"
FileExt = "*.csv"
If Right(FromPath, 1) <> "\" Then
FromPath = FromPath & "\"
End If
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub
End If
If FSO.FolderExists(ToPath) = False Then
MsgBox ToPath & " doesn't exist"
Exit Sub
End If
FSO.MoveFile Source:=FromPath & FileExt, Destination:=ToPath
MsgBox "Files have been moved" '"You can find the files from " & FromPath & " in " & ToPath
Exit Sub
Handler: MsgBox "There is a problem with the data files"
End Sub