How to copy files in VBA?

Posted on 2007-07-31
Medium Priority
Last Modified: 2012-05-05
Hello - How can I copy the contents of one folder to another folder in VBA (Access 2003) ?
(assume it's ok to overwrite existing files with the same name in the destination folder)


Question by:mlagrange
  • 2
LVL 61

Accepted Solution

mbizup earned 2000 total points
ID: 19600921
Make sure you have the reference for MS SCripting Runtime checked.

Then use this VBA:

    Dim fso As New Scripting.FileSystemObject
    fso.CopyFolder "C:\MyFolder", "C:MyNewFolder", True
LVL 33

Expert Comment

ID: 19600924
Using VBA.

Before that, you need to add a reference
Tools -> References
Check "Microsoft Scripting Runtime".

    Dim fso As New FileSystemObject
    fso.CopyFolder "C:\Folder1", "C:\Folder2", True
    Set fso = Nothing

Author Comment

ID: 19602250
Thanks a million! The FSO is a wonderful thing!

LVL 61

Expert Comment

ID: 19602462
Glad to help :-)

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month15 days, 16 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question