#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default copy files

Hi.

How to write a code to copy all the ".xls" files in D:\1 to D:\2 ?

thanks.


  #2   Report Post  
Posted to microsoft.public.excel.programming
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.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy files to clipboard wyn Excel Discussion (Misc queries) 0 July 30th 08 12:15 PM
Copy and Paste Between Files Dragon Excel Discussion (Misc queries) 1 February 5th 07 04:26 AM
Copy Files desmondleow[_16_] Excel Programming 5 April 21st 04 08:11 PM
Copy values between files. Ron[_20_] Excel Programming 0 March 4th 04 12:03 AM
copy files from one dir to another rvik[_14_] Excel Programming 7 February 13th 04 01:30 PM


All times are GMT +1. The time now is 11:50 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"