WD: Macro Command for Copying Files

Last reviewed: February 2, 1998
Article ID: 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 95, versions 7.0, 7.0a
  • 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.

MORE INFORMATION

Word for Windows

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

   Sub MAIN
      CopyFile "C:\winword\test.doc", "C:\backup"
   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$, "b:\"     '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 "Macintosh HD:Desktop Folder:Word Document"

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

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

REFERENCES

"Using WordBasic," by WexTech Systems and Microsoft, page 166


Additional query words: copy file macword
Keywords : kbhowto kbmacroexample winword winword2 word6 word7 word95 kbmacro
Version : WINDOWS:2.0,2.0a,2.0a-CD,2.0b,2.0c,6.0,6.0a,6.0c,7.0,7.0a; MACINTOSH:6.0,6.0.1,6.0.6.0.1a
Platform : MACINTOSH WINDOWS
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 2, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.