Backup copy

D

daniel chen

I want to make a backup copy of file from C:\Dir_try to F:\Dir_try.
The following code is not working. Please help me to correct it.

Shell Environ("comspec") & " /c copy " _
& Chr(34) & "C:\Dir_try\fundacf.xls F:\Dir_try\fundacf.xl"
 
B

BrianB

If you just want to copy a file you can use VBA FileCopy.
FileCopy source, destination
where both arguments are path strings/filenames
 
D

daniel chen

Thank you, Brian
I tried. It worked fine for a single file for each line.
In fact, I was looking for a batch execution using (*) - a wild card.
Currently, I am using a batch program in a separate operation.
copy "C:\Dir_try\fund*.xls" "F:\Dir_try\fund*.xls"
How might I do to incorporate it into Excel?
 
D

Dana DeLouis

One can use wildcard characters with "FileSystemObject".

Sub CopyFiles(sFrom As String, sTo As String)
On Error Resume Next
With CreateObject("Scripting.FileSystemObject")
'True for overwrite
.CopyFile sFrom, sTo, True
End With
End Sub

Sub TestIt()
CopyFiles "C:\Dir_try\fund*.xls", "F:\BackupFolder"
End Sub


HTH. :>)

--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


daniel chen said:
Thank you, Brian
I tried. It worked fine for a single file for each line.
In fact, I was looking for a batch execution using (*) - a wild card.
Currently, I am using a batch program in a separate operation.
copy "C:\Dir_try\fund*.xls" "F:\Dir_try\fund*.xls"
How might I do to incorporate it into Excel?
 
Top