ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Copy file with a macro (https://www.excelbanter.com/excel-discussion-misc-queries/132972-copy-file-macro.html)

Brettjg

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

Chip Pearson

Copy file with a macro
 
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)



"Brettjg" wrote in message
...
I want to copy a file from one folder to another with a macro. Can someone
help please?




Brettjg

Copy file with a macro
 
Thankyou Chip

"Chip Pearson" wrote:

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)



"Brettjg" wrote in message
...
I want to copy a file from one folder to another with a macro. Can someone
help please?






All times are GMT +1. The time now is 11:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com