Move Files (Need a tweek) (1 Viewer)

ECEK

Registered User.
Local time
Today, 00:49
Joined
Dec 19, 2012
Messages
717
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.
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
 

Peter Reid

Registered User.
Local time
Today, 00:49
Joined
Dec 3, 2003
Messages
134
One way would be to replace

Code:
FSO.MoveFile Source:=FromPath & FileExt, Destination:=ToPath

with

Code:
FSO.MoveFile Source:=FromPath & "FileOne.csv", Destination:=ToPath
FSO.MoveFile Source:=FromPath & "FileTwo.csv", Destination:=ToPath
FSO.MoveFile Source:=FromPath & "FileThree.csv", Destination:=ToPath
FSO.MoveFile Source:=FromPath & "FileFour.csv", Destination:=ToPath
 

Users who are viewing this thread

Top Bottom