Return an Excel Workbook File Name or Active Worksheet Name
Question details
The user wants formulas that return only the current workbook file name or the active worksheet name in Excel.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- The user needs to extract workbook and worksheet metadata for use in cells, reports, headers, or formulas.
- Observed behavior
- CELL("filename") returns the full file path together with the workbook name and worksheet name after the workbook has been saved.
Save the workbook first, because CELL("filename") does not return workbook and worksheet information for an unsaved file. Enter the formula on the worksheet whose name you want to display.
Use TEXTAFTER and TEXTBEFORE in Excel 365
Use this option in the Excel desktop app when TEXTAFTER and TEXTBEFORE are available.
CELL("filename") returns a string in the form C:\Folder\[Workbook.xlsx]Sheet1. The formulas below isolate the text after or between the square brackets.
Select File > Save, then save the workbook with a file name before entering the formula.
Click the cell where you want the sheet name to appear and enter =TEXTAFTER(CELL("filename"),"]",-1). Press Enter.
Click another cell and enter =TEXTBEFORE(TEXTAFTER(CELL("filename"),"["),"]"). Press Enter to return the file name without its folder path.
If you rename the workbook or worksheet and the result does not refresh, press F9 or use Formulas > Calculate Now.

Use MID and FIND when TEXTAFTER is unavailable
Use this compatibility formula when your Excel version does not include TEXTAFTER or TEXTBEFORE.
Display the Current Workbook and Worksheet Name in WPS Spreadsheets
WPS Spreadsheets lets you use CELL("filename") with text formulas to show the saved workbook name or current worksheet name directly in a cell. This is useful for dynamic report labels, print layouts, and worksheet documentation.
- 1. Open and save the spreadsheet: Open the file in WPS Spreadsheets and select Menu > Save As or Save to ensure the workbook has a saved name.
- 2. Add a worksheet name formula: Select an output cell and enter =MID(CELL("filename"),FIND("]",CELL("filename"))+1,255).
- 3. Add a workbook name formula: Select another cell and enter =MID(CELL("filename"),FIND("[",CELL("filename"))+1,FIND("]",CELL("filename"))-FIND("[",CELL("filename"))-1).
- 4. Refresh the displayed metadata: After renaming the file or sheet, recalculate the workbook or reopen the file if the displayed result has not updated.

Frequently Asked Questions
Why does CELL("filename") return an error or blank result?
The workbook usually has not been saved yet. Use File > Save, assign a file name, and then recalculate the formula with F9 if necessary.
How can I return only the worksheet name in Excel 365?
In a cell on the target worksheet, enter =TEXTAFTER(CELL("filename"),"]",-1). The text after the closing bracket is the active worksheet name.
How do I remove the folder path from an Excel workbook name?
Use =TEXTBEFORE(TEXTAFTER(CELL("filename"),"["),"]") in Excel 365. It returns the text between [ and ], which is the workbook file name.
Can I use these formulas in Excel for the web?
They may not work reliably in Excel for the web because CELL("filename") and related workbook metadata can have limitations there. Use the Excel desktop app when possible.
Will the formula update after I rename a worksheet?
It should update after recalculation. If the old name remains visible, press F9, choose Formulas > Calculate Now, or reopen the workbook.




