See Also Example
Copies a file.
FileCopy srcfile, destfile
The FileCopy statement has these parts:
srcfile Any string expression that contains an unambiguous (no wildcards) file specification for the file to copy. The file specification may include optional drive and path information.
destfile Any string expression that contains an unambiguous (no wildcards) file specification for the file where srcfile is to be copied. The file specification may also include optional drive and path information.
You cannot copy a file that is already opened by Visual Basic for anything but read-only access.
FileCopy Statement Example
The example uses FileCopy to copy one file to another. When you choose the name of a file in the file list box, you are prompted to enter a destination file name. To try this example, paste the code into the Declarations section of a form that contains a file list box named File1. Then press F5 to start.
Sub File1_Click ()
Dim DestFile, Msg ' Declare variables.
On Error GoTo ErrHandler
DestFile = InputBox("Copy to where?")
FileCopy File1.FileName, DestFile ' Copy file to destination.
If Err = 55 Then ' File already open.
MsgBox "Cannot copy an open file. Close it and try again."
MsgBox "You must specify a complete destination file name."