Microsoft KB Archive/121858

= Microsoft Knowledge Base =

XL5: Returning the Filename to a Cell in the Worksheet
Last reviewed: September 12, 1996

Article ID: Q121858

The information in this article applies to:


 * Microsoft Excel for Windows, versions 3.x, 4.0, 4.0a, 5.0
 * Microsoft Excel for the Macintosh, versions 3.x, 4.0, 5.0

SUMMARY
To return the filename of a worksheet can to a cell in the document, use the appropriate formula below.

If you are using Microsoft Excel for Windows
=MID(CELL("filename"),MAX(IF(MID(CELL("filename"),ROW(1:256),1)="\",   ROW(1:2 56)))+1,255) NOTE: This formula should be entered on one single line, and it must be entered as an array formula. (To enter a formula as an array formula in Microsoft Excel for Windows, press CTRL+SHIFT+ENTER.) Note also that CELL("filename") returns the full path and filename for the file.

If you are using Microsoft Excel for the Macintosh
=MID(CELL("filename"),MAX(IF(MID(CELL("filename"),ROW(1:256),1)=":",   ROW(1:256)))+1,255) NOTE: This formula should be entered on one single line, and it must be entered as an array formula. (To enter a formula as an array formula in Microsoft Excel for the Macintosh, press COMMAND+RETURN.) Note also that CELL("filename") returns the full path and filename for the file.

MORE INFORMATION
There is currently no single worksheet function that returns only the filename to a cell. However, you can create a Visual Basic, Applications Edition, procedure that uses ActiveWorkBook.Name to return the name of the active workbook to a cell.