davesexcel.com

Excel information

Most Popular Excel Questions

Copy File from one folder to another folder

Posted by davesexcel on March 30, 2013 at 1:25 PM

Copy a file from one folder to another folder


This will copy one file from a folder to another folder


Sub CopyToDifferentFolder()

    FileCopy "C:\Users\Dave\Downloads\SourceFolder\OriginalWorkbook.xlsm", _

             "C:\Users\Dave\Downloads\DestinationFolder\OriginalWorkbook.xlsm"

End Sub



This will copy one file from a folder to another folder and rename it.


Sub CopyToDifferentFolder_Rename()

    FileCopy "C:\Users\Dave\Downloads\SourceFolder\OriginalWorkbook.xlsm", _

             "C:\Users\Dave\Downloads\DestinationFolder\NewWorkbook.xlsm"

End Sub



Copy 2 files from folder to another folder


Sub CopyFiles()

    Dim SrceFile1, SrceFile2

    Dim DestFile1, DestFile2

    SrceFile1 = "C:\SourceFolder\Source1.xls"

    SrceFile2 = "C:\SourceFolder\Source2.xls"

    DestFile1 = "C:\DestinationFolder\Source1.xls"

    DestFile2 = "C:\DestinationFolder\Source2.xls"

    FileCopy SrceFile1, DestFile1

    FileCopy SrceFile2, DestFile2

End Sub

 

 


Copy 2 files from folder to another folder and rename file


Sub CopyFileNewname()

    Dim SrceFile1, SrceFile2

    Dim DestFile1, DestFile2

    SrceFile1 = "C:\SourceFolder\Source1.xls"

    SrceFile2 = "C:\SourceFolder\Source2.xls"

    DestFile1 = "C:\DestinationFolder\New1.xls"

    DestFile2 = "C:\DestinationFolder\New2.xls"

    FileCopy SrceFile1, DestFile1

    FileCopy SrceFile2, DestFile2

End Sub


You may want to copy files from one folder to another folder and rename the files with a Date and Time Stamp. Some people want to do this for back-up reasons.


Sub CopyFileAddDate()

    Dim SrceFile1, SrceFile2

    Dim DestFile1, DestFile2

    SrceFile1 = "C:\SourceFolder\Source1.xls"

    SrceFile2 = "C:\SourceFolder\Source2.xls"

    DestFile1 = "C:\DestinationFolder\Source1 " & Format(Now, "yyyy-mm-dd hh-mm-ss") & ".xls"

    DestFile2 = "C:\DestinationFolder\Source2 " & Format(Now, "yyyy-mm-dd hh-mm-ss") & ".xls"

    FileCopy SrceFile1, DestFile1

    FileCopy SrceFile2, DestFile2

End Sub

 

 





 

 

 

 

Categories: None

Post a Comment

Oops!

Oops, you forgot something.

Oops!

The words you entered did not match the given text. Please try again.

You must be a member to comment on this page. Sign In or Register

0 Comments