Task Scheduler or VBA to simple copy periodically folders contents toexternal drive

U

u473

I need to copy periodically all files (without any other data
manipulation)
from folders W, X, Y on Drive C to folder Z on Drive D.
Any existing files would ge ovewritten without prompting.
Is it more convenient to process this through Windows Task Scheduler
or through VBA ?

Help appreciated,

J.P.
 
C

Chip Pearson

If you need to work only with files, not subfolders, you can use code
like the following:


Sub AAA()
Dim FromFolders As Variant
Dim ToFolder As String
Dim N As Long
Dim FName As String
FromFolders = Array("C:\Test", "C:\Test2")
ToFolder = "D:\Z"
Application.DisplayAlerts = False
For N = LBound(FromFolders) To UBound(FromFolders)
ChDrive FromFolders(N)
ChDir FromFolders(N)
FName = Dir("*.*", vbNormal)
Do Until FName = vbNullString
On Error Resume Next
Kill ToFolder & "\" & FName
On Error GoTo 0
Name FName As ToFolder & "\" & FName
FName = Dir()
Loop
Next N
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top