COPYING

J

Jim/Chris

I do not know how to do it in a macro but here is the code

Private Sub Command10_Click()
This works even if you are in the application

Dim fso As Variant
Dim boverwrite As Boolean

Set fso = CreateObject("Scripting.fileSystemObject")

fso.copyfile "sourcefile", "destinationfile"

End Sub

Jim
 
D

Douglas J. Steele

Just because FSO lets you copy the file even if it's open doesn't mean it's
a good idea to do so. It's entirely possible that your copy will be
inconsistent if other actions are going on concurrently.

I think it's much safer to use the built-in VBA FileCopy statement:

Private Sub Command10_Click()

FileCopy "sourcefile", "destinationfile"

End Sub

(and in your example, it would be better to declare fso as an Object, not as
a Variant. It might also be a good idea to have Set fso = Nothing at the
end.)
 
Top