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.


KBCategory: kbusage
KBSubcategory:

Additional reference words: 5.00 4.00 3.00 4.00a



THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 12, 1996
©1997 Microsoft Corporation. All rights reserved. Legal Notices.