Copy file with a macro

B

Brettjg

I want to copy a file from one folder to another with a macro. Can someone
help please?
 
C

Chip Pearson

Use the FileCopy command:


Sub CopyAFile()
Dim FromFileName As String
Dim ToFileName As String
FromFileName = "C:\Test\FileToCopy.txt"
ToFileName = "C:\Test2\FileToCopy.txt"
FileCopy Source:=FromFileName, Destination:=ToFileName
End Sub

Note that destination folder must exist, otherwise you'll get a "Path Not
Found" error. Use the MkDir function to create a new folder if necessary.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)
 
B

Brettjg

Thankyou Chip

Chip Pearson said:
Use the FileCopy command:


Sub CopyAFile()
Dim FromFileName As String
Dim ToFileName As String
FromFileName = "C:\Test\FileToCopy.txt"
ToFileName = "C:\Test2\FileToCopy.txt"
FileCopy Source:=FromFileName, Destination:=ToFileName
End Sub

Note that destination folder must exist, otherwise you'll get a "Path Not
Found" error. Use the MkDir function to create a new folder if necessary.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)
 
Top