Table of contents
Collapse the table of content
Expand the table of content

Name Statement

office 365 dev account|Last Updated: 1/23/2018
2 Contributors

Renames a disk file, directory, or folder.



The Name statement syntax has these parts:

oldpathnameRequired. String expression that specifies the existing file name and location — may include directory or folder, and drive.
newpathnameRequired. String expression that specifies the new file name and location — may include directory or folder, and drive. The file name specified by newpathname can't already exist.

Remarks The Name statement renames a file and moves it to a different directory or folder, if necessary. Name can move a file across drives, but it can only rename an existing directory or folder when both newpathname and oldpathname are located on the same drive. Name cannot create a new file, directory, or folder. Using Name on an open file produces an error. You must close an open file before renaming it. Namearguments cannot include multiple-character ( \* ) and single-character ( ? ) wildcards.


This example uses the Name statement to rename a file. For purposes of this example, assume that the directories or folders that are specified already exist. On the Macintosh, "HD:" is the default drive name and portions of the pathname are separated by colons instead of backslashes.

Dim OldName, NewName 
OldName = "OLDFILE": NewName = "NEWFILE" ' Define file names. 
Name OldName As NewName ' Rename file. 

Name OldName As NewName ' Move and rename file. 
© 2018 Microsoft