Microsoft KB Archive/86709

{|
 * width="100%"|

WD: Macro Command for Copying Files

 * }

Q86709

-

The information in this article applies to:


 * Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
 * Microsoft Word for Windows, versions 7.0, 7.0a
 * Microsoft Word for the Macintosh, versions 6.0, 6.0.1, 6.0.1a

-

SUMMARY
In Microsoft Word, the WordBasic CopyFile command allows a specified file to be copied to another directory location. The syntax and function of this command are similar to those of the MS-DOS Copy command.

Word for Windows
The following macro copies the Test.doc file from the C:\Winword directory to the C:\Backup directory:

  Sub MAIN CopyFile &quot;C:\winword\test.doc&quot;, &quot;C:\backup&quot; End Sub NOTE: If a file of the same name already exists in the target directory, a message asking if you want to replace the existing file is displayed.

Syntax:

CopyFile Filename$, Directory$ If a drive and directory are not specified in the Filename$ parameter, Word for Windows copies the specified file from the current directory.

The Directory$ parameter for the CopyFile command should include the full path of the directory to which you want to copy the file.

The following sample macro copies the active document file to drive B:

  Sub MAIN FileSave              'save the current file a$ = FileName$      'get the current filename CopyFile a$, &quot;b:\&quot;    'copy the active file to the B drive End Sub NOTE: The CopyFile command is not available in version 1.x of Word for Windows.

NOTE: Information provided in this document is provided 'as is' without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Word 6.x for the Macintosh
For Macintosh users the syntax for CopyFile is the same as above:

CopyFile .FileName = text, .Directory = text The .Directory parameter specifies the folder path to the file's location or to where it is to be saved. For example &quot;Macintosh HD:Desktop Folder:Word Document&quot;

The following macro will make a copy of the file named &quot;Test&quot; in the Microsoft Word 6 folder and save it to the desktop.

  Sub MAIN CopyFile &quot;Mac HD:Microsoft Office:Microsoft Word 6:Test&quot;, &quot;Mac \ HD:Desktop Folder:Test&quot; End Sub