Skip to main content

FileCopy statement

Table of contents
  1. Syntax
  2. Remarks
  3. Example

Copies a file.

Syntax

FileCopy source, destination

The FileCopy statement syntax has these named arguments:

Part Description
source Required. String expression that specifies the name of the file to be copied. The source may include directory or folder, and drive.
destination Required. String expression that specifies the target file name. The destination may include directory or folder, and drive.

Remarks

If you try to use the FileCopy statement on a file that is currently open, an error occurs.

Example

This example uses the FileCopy statement to copy one file to another. For the purposes of this example, assume that the file contains some data.

Dim SourceFile, DestinationFile 
SourceFile = "SRCFILE" ' Define source file name. 
DestinationFile = "DESTFILE" ' Define target file name. 
FileCopy SourceFile, DestinationFile ' Copy source to target.

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>