FileCopy Statement

See AlsoJ59HZ1              Example8PNHH>Low

Copies a file.

Syntax

FileCopy srcfile, destfile

Remarks

The FileCopy statement has these parts:

Part               Description

 

srcfile            Any string expression1330R89 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.


See Also

Kill Statement4K6UYKK

Name Statement103GSXJ


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.

   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