Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy FIle 1

Status
Not open for further replies.

Hawkide

Technical User
Oct 8, 2003
159
US
How can I copy a file from one folder to another using VBA? I could probably use a shell command, but there must be another way. TIA...
 
If you're just putting the file into a different folder on the same drive, you can use the Name command:

Name (Filename) as (Newname)



 
I found it to be easier and more robust not to use FileCopy or Name and just use the SHFileOperation API function as it gives you much more flexibility, and if there is an error, it won't raise it (gives you back the error code) and create handling headaches for you.

Also, though you'd think Name would just do a rename, it actually does a copy followed by a delete. Try it on a large file - it should be instantaneous, but, you can watch in Explorer as it does the copy. The SHFileOperation let's you do a real rename - and again, many more options than what VB provides you with.

 
I want to copy *.txt to floppy drive
What should I do with Myfilecopy?
Myfilecopy("*.txt","A:")?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top