See Also Example
Copies a file.
Syntax
FileCopy srcfile, destfile
Remarks
The FileCopy statement has these parts:
Part Description
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.
Kill Statement
Name Statement
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.
Exit Sub
ErrHandler:
If Err = 55 Then ' File already open.
MsgBox "Cannot copy an open file. Close it and try again."
Else
MsgBox "You must specify a complete destination file name."
End If
Resume Next
End Sub