Excel.Tips.Net ExcelTips (Menu Interface)

Renaming a File

Summary: Need to rename a file in a macro? It's easy to do using the Name command, as discussed in this tip. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, Excel 2003, and Excel 2007.)

Your macros can rename a file by using the Name command. This is a holdover from other versions of BASIC. The syntax is:

Name OldFile As NewFile

where OldFile is the name of the old file, and NewFile is the name of the new file. Both filenames must either be string variables or be enclosed in quotes. Both filenames can contain complete path names, but both must be on the same disk drive. If the path names differ, then the command also has the side benefit of moving the file from one directory to another.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2364) applies to Microsoft Excel versions: 97 | 2000 | 2002 | 2003 | 2007

Related Tips:

Your Data, Your Way! Want the greatest control possible over how your data appears on the page? Excel's custom formats can provide that control, and ExcelTips: Custom Formats can unlock the secrets to creating your own custom formats. Check out ExcelTips: Custom Formats today!