WD: Using the WordBasic Name...As Command to Rename FilesLast reviewed: March 12, 1998Article ID: Q86714 |
The information in this article applies to:
SUMMARYIn Microsoft Word, the WordBasic Name...As command allows a specified file to be renamed to another file name. The syntax and function of this command is similar to the MS-DOS RENAME command. Syntax:
Name OldName$ As NewName$The following macro renames the TEST.DOC file to TEST2.DOC:
Name "c:\winword\test.doc" As "c:\winword\test2.doc"If you do not include paths with the OldName$ and NewName$ arguments, Name...As assumes the current directory (the directory selected in the Open dialog box on File menu). By including a different path for NewName$, you can move a file to a different directory. You cannot use Name to move directories or to move a file to a different drive.
MORE INFORMATIONWARNING: ANY USE BY YOU OF THE <CODE OR MACRO CODE> PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this <code or macro code> "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. If a file of the same name already exists in the target directory, Word 6.x for Windows will post WordBasic error number 102 (Command Failed). The filename you choose to rename the file to, must not already exist in the directory. The following Word 6.x example macro demonstrates how to trap for error numbers 102 (Command Failed) and 53 (File not Found).
Sub MAIN On Error Resume Next Name "c:\winword\test.doc" As "c:\winword\test2.doc" If err = 102 Then MsgBox "File rename error occurred." If err = 53 Then MsgBox "File not found." End SubNOTE: Word 6.x for the Macintosh users, be sure to use Mac path information on the Name...As line. For example:
Name "Mac HD:Desktop Folder:Test Document" As "Mac HD:Desktop \ Folder:Regular Document"The WordBasic CopyFile statement allows you to copy a file to a specified directory. Like the MS-DOS COPY command, CopyFile allows you to specify a new name when copying the file.
Syntax
CopyFile .FileName = text, .Directory = text REFERENCES"Using WordBasic," by WexTech Systems and Microsoft, page 258
|
Additional query words: Name
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |