Inserting the current Excel file name in a cell

Applies to
Microsoft Excel 2002

 Note   The parameter "filename" referred to in the CELL function in this article is literally the word "filename", in quotation marks.

Insert the current file name, its full path, and the name of the active worksheet (for example, C:\Excel\[test.xls]Testsheet)

Enter the following formula in the cell in which you want to display the current file name with its full path and the name of the current worksheet:

=CELL("filename")

Insert the current file name and the name of the active worksheet (for example, [text.xls]Testsheet)

Enter the following formula as an array formula to display the current file name and active worksheet name:

=RIGHT(CELL("filename"),LEN(CELL("filename"))- MAX(IF(NOT(ISERR(SEARCH("\",CELL("filename"), ROW(1:255)))),SEARCH("\",CELL("filename"),ROW(1:255)))))

 Notes 

  • To enter a formula as an array formula, press CTRL+SHIFT+ENTER.
  • The formula returns the name of the worksheet as long as the worksheet has been saved at least once. If you use this formula on an unsaved worksheet, the formula cell will remain blank until you save the worksheet.

Insert the current file name only (for example, test.xls)

Enter the following formula to insert the name of the current file in a cell:

=MID(CELL("filename"),SEARCH("[",CELL("filename"))+1, SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1)

 Note   If you use this formula on an unsaved worksheet, you receive the error #VALUE!. When you save the worksheet, the error is replaced by the filename.