normalMoving/copying files from one folder to another based on an Excel sheet

More
1 month 1 week ago #2520 by Lewis-H
Please try it like this.
Copy or Move one file
For one file you can use the VBA Name and FileCopy function and for entire folders or a lot of files use the other macro example's on this page.
Sub Copy_One_File()
    FileCopy "C:\Users\Ron\SourceFolder\Test.xls", "C:\Users\Ron\DestFolder\Test.xls"
End Sub
Sub Move_Rename_One_File()
'You can change the path and file name
    Name "C:\Users\Ron\SourceFolder\Test.xls" As "C:\Users\Ron\DestFolder\TestNew.xls"
End Sub
Copy or move more files or complete folders
Note: Read the commented code lines in the code
Sub Copy_Folder()
'This example copy all files and subfolders from FromPath to ToPath.
'Note: If ToPath already exist it will overwrite existing files in this folder
'if ToPath not exist it will be made for you.
    Dim FSO As Object
    Dim FromPath As String
    Dim ToPath As String
    FromPath = "C:\Users\Ron\Data"  '<< Change
    ToPath = "C:\Users\Ron\Test"    '<< Change
    'If you want to create a backup of your folder every time you run this macro
    'you can create a unique folder with a Date/Time stamp.
    'ToPath = "C:\Users\Ron\" & Format(Now, "yyyy-mm-dd h-mm-ss")
    If Right(FromPath, 1) = "\" Then
        FromPath = Left(FromPath, Len(FromPath) - 1)
    End If
    If Right(ToPath, 1) = "\" Then
        ToPath = Left(ToPath, Len(ToPath) - 1)
    End If
    Set FSO = CreateObject("scripting.filesystemobject")
    If FSO.FolderExists(FromPath) = False Then
        MsgBox FromPath & " doesn't exist"
        Exit Sub
    End If
    FSO.CopyFolder Source:=FromPath, Destination:=ToPath
    MsgBox "You can find the files and subfolders from " & FromPath & " in " & ToPath
End Sub

Please Log in or Create an account to join the conversation.

More
1 year 1 week ago #1809 by jh@eerno.com
I'm trying to use the vba code posted on the web to move files from one folder to another folder using file names in an Excel sheet.  I'm
running Windows 10.
The code does not work; it does nothing.  I see in the code refers to "Kutools Excel".  Do I have to have Kutools
installed for this code to run???

Thanks,
JH

Please Log in or Create an account to join the conversation.

Moderators: jaychivoExcelfansqiuhongkun