Visual Basic for Applications Reference

Name Statement Example

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.  

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

OldName = "C:\MYDIR\OLDFILE": NewName = "C:\YOURDIR\NEWFILE"
Name OldName As NewName   ' Move and rename file.