Thread: copy files
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default copy files

Young-Hwan,

This is one way...
You can use code from the Microsoft Scripting Runtime Library.
It is included in all recent versions of windows.
Please try this first on files you don't care about.
If it throws an error there is no undo.
"-----------------------------------------------

'Requires reference to "Microsoft Scripting Runtime" in the VBA project.
'Assumes "1" and "2" are folders.
'By replacing "CopyFile" with "MoveFile" you can do just that.
'Jim Cone, June 13, 2004

Sub CopyFilesWithScriptingRuntime()
Dim strFromPath As String
Dim strToPath As String

Dim Fso As Scripting.FileSystemObject
Set Fso = New Scripting.FileSystemObject

'Wildcards only allowed in the "from" path and only at the end.
strFromPath = "D:\1\*.xls"
strToPath = "D:\2"

'False prevents overwriting of files
Fso.CopyFile strFromPath, strToPath, False

'Technically not required, but I prefer it.
Set Fso = Nothing
End Sub
'-----------------------------------------------
Regards,
Jim Cone
San Francisco, CA


"Young-Hwan Choi" wrote in message ...
Hi.
How to write a code to copy all the ".xls" files in D:\1 to D:\2 ?
thanks.