To return the current workbook’s file name in Excel, use =TEXTBEFORE(TEXTAFTER(CELL("filename",A1),"["),"]") in Microsoft 365 or Excel 2024. The workbook must have been saved at least once; for older Excel versions, use the compatible formula below.
The formula that returns the workbook name
Assume you enter the formula on the worksheet whose workbook name you want, and A1 is a cell on that worksheet. In Microsoft 365 or Excel 2024, enter:
=TEXTBEFORE(TEXTAFTER(CELL("filename",A1),"["),"]")
If Excel identifies the workbook as C:\Reports\[Quarterly Sales.xlsx]Summary, this formula returns Quarterly Sales.xlsx. It includes the file extension, such as .xlsx, .xlsm, or .xls. This is often the most useful result when a report needs to identify the source workbook without displaying its entire folder location or worksheet name.
For versions without TEXTAFTER and TEXTBEFORE, use this older, broadly compatible formula. It has the same cell assumption: A1 is a cell on the worksheet containing the formula.
=MID(CELL("filename",A1),FIND("[",CELL("filename",A1))+1,FIND("]",CELL("filename",A1))-FIND("[",CELL("filename",A1))-1)
The older formula finds the opening and closing square brackets in Excel’s returned location string, then extracts the text between them. With the example above, it also returns Quarterly Sales.xlsx. If your Excel uses a regional list separator other than a comma, formulas may need that local separator; the examples here use comma separators.
How CELL("filename") works
CELL("filename",A1) is the part that supplies the information. CELL is an Excel information function, and its first argument tells it what kind of detail to return. With the filename option, it returns a string containing the workbook’s location, workbook name, and current worksheet name. The other parts of the extraction formulas separate those pieces.
For example, the returned string may look like C:\Reports\[Quarterly Sales.xlsx]Summary. The folder path comes before the square-bracketed workbook name, while the worksheet name follows the closing bracket. The exact path depends on where and how the workbook is stored. A local file may show a drive and folder; a cloud or network location can be represented differently depending on Excel and the storage setup.
The A1 reference is not a request to read the contents of A1. It identifies a cell in the worksheet whose workbook and sheet details Excel should report. You can use another cell on that same sheet instead. If you copy the formula to a different worksheet, it will report the workbook and sheet for the new location.
Save the workbook before using the formula
A common surprise is a blank result. Excel may return an empty string for the filename information when the workbook has never been saved. Save the workbook first using File > Save As, choose a name and location, and then check the formula again. If you have just created a new workbook, giving it its first saved name is essential: until then, there is no saved file name or folder path for the function to report.
After a workbook is renamed or moved, the displayed result may not refresh immediately. Recalculate the worksheet with F9 on Windows; on a Mac, use Fn+F9 if the function keys are assigned to hardware controls. If the value still looks stale, save and reopen the workbook, then check again. The function reports workbook information, not a permanent record of the original name, so a changed location or name can change its output.
Also distinguish a blank result from an error. A blank often points to an unsaved workbook. An error such as #NAME? is more likely to mean that Excel does not recognize a function in the formula, as can happen when using TEXTAFTER or TEXTBEFORE in an older release.
Return the full path or just the sheet name
Sometimes the complete location is more useful than just the workbook name. Assume A1 is a cell on the worksheet you want to identify. To return the full filename string, including the path and worksheet, use:
=CELL("filename",A1)
This produces a result in the style of C:\Reports\[Quarterly Sales.xlsx]Summary. It is useful for audit sheets or internal reports where readers need to see which workbook and tab they are viewing. Keep in mind that the full string can be long and may expose folder names, so it is not always appropriate to display in a document shared outside your organization.
To return only the worksheet name in Microsoft 365 or Excel 2024, assume A1 is on the sheet in question and use:
=TEXTAFTER(CELL("filename",A1),"]")
For the example path, the result is Summary. The workbook-name formula and sheet-name formula use the same underlying string; they simply extract text from opposite sides of the closing bracket. If you need all three parts, it is usually clearer to put the full path, workbook name, and sheet name in separate cells rather than try to make one formula serve every purpose.
Choose a formula for your Excel version
TEXTBEFORE and TEXTAFTER make the newer formula shorter and easier to read, but they require Microsoft 365 or Excel 2024. In Excel 2021 or an earlier version, the MID and FIND formula is the safer choice. If you share a workbook with colleagues using different Excel releases, using the older formula can reduce compatibility problems.
Check the version and the result before distributing a workbook. A formula containing a function unavailable to a recipient may display #NAME? on their computer, even if it works for you. The CELL function itself is available in many Excel releases, which is why the longer extraction formula remains a practical option for older workbooks. Excel for the web can calculate common worksheet formulas, but if a result does not refresh as expected, open the file in desktop Excel and recalculate it.
These formulas return the name of the workbook that contains the referenced cell. They do not ask Excel to look up an unrelated file’s name from a folder, and they do not provide a general-purpose file browser. If you need to list or inspect many files in a directory, a formula based on CELL is not the right tool.
Useful ways to display the result
A filename formula can make a workbook easier to identify when it is printed, exported, or reviewed later. For example, you might place it near a report title, in a source-information cell, or in a cover-sheet field. Consider labeling the result, such as “Workbook,” so readers understand whether they are seeing the file name, full path, or sheet name.
For a report with separate cells for the workbook and sheet, assume A1 is on the worksheet being identified. Use the workbook-name formula in one cell and the sheet-name formula in another. In Microsoft 365 or Excel 2024, those formulas are:
=TEXTBEFORE(TEXTAFTER(CELL("filename",A1),"["),"]")returns the workbook name, including its extension.=TEXTAFTER(CELL("filename",A1),"]")returns the worksheet name.
For example, if the workbook is Quarterly Sales.xlsx and the current tab is Summary, the two cells display those two values separately. This arrangement is usually easier to format and less prone to confusion than showing a full path in a narrow cell. You can widen the column, enable Wrap Text, or use a smaller font if the displayed value needs more room.
Common problems and fixes
- The result is blank: Save the workbook at least once, then recalculate. An unsaved workbook does not yet have a saved file location for CELL to report.
- You see #NAME?: Check for misspelled function names and confirm that your Excel version supports TEXTAFTER and TEXTBEFORE. Use the MID/FIND alternative in older versions.
- You see the entire path instead of only the name: The formula may be just
=CELL("filename",A1). Use an extraction formula if you want only the text between the square brackets. - The result has the wrong sheet name: Make sure the reference, such as A1, belongs to the worksheet you intend to identify. A formula copied to another tab reports that tab’s information.
- The result seems outdated: Recalculate with F9, save the workbook, or close and reopen it after moving or renaming the file.
One further distinction matters: the formula returns the workbook’s name as Excel identifies it, including the extension. It does not automatically remove .xlsx or another suffix. If a report needs a shortened display, you can use cell formatting or a separate text formula, but do not remove the extension if readers need to distinguish file types.
Frequently Asked Questions
What is the simplest Excel formula to show the file name?
In Microsoft 365 or Excel 2024, with A1 on the worksheet, use =TEXTBEFORE(TEXTAFTER(CELL("filename",A1),"["),"]"). It returns the workbook name with its extension, provided the workbook has been saved.
Can Excel show the file name without the folder path?
Yes. Use the extraction formula above rather than =CELL("filename",A1), which returns the longer location string containing the folder path, workbook name, and sheet name.
Why does CELL("filename") return nothing?
The workbook may not have been saved yet. Save it to a location with a file name, then recalculate. If it is already saved, check that the formula refers to a cell on the worksheet you mean to identify.
Can I get the worksheet name with a formula?
Yes. In Microsoft 365 or Excel 2024, use =TEXTAFTER(CELL("filename",A1),"]"), with A1 on the desired worksheet. It returns the tab name after the closing bracket.
Does this formula update if I rename the workbook?
It reports the workbook information available to Excel, so the displayed value can change after a rename or move. If it does not update straight away, recalculate or reopen the workbook and verify the result.
Related
- Excel Data Validation Source: Lists, Ranges, and Rules
- Excel Data Validation Rules: How They Work and When to Use Them
- Excel Data Validation Restrictions and Their Limits
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Formulas & functions
- WEEKDAY Function in Excel: Find the Day of the WeekExcel’s WEEKDAY function returns a number for the day of the week represented by a date. If cell…
- Excel Time Between Two Timestamps: Formulas and TipsIf the start timestamp is in A2 and the end timestamp is in B2, enter =B2-A2 to calculate…
- Named Ranges in XLOOKUP: How to Use Them in ExcelTo use a named range in XLOOKUP, replace a cell reference such as A2:A6 with the range’s name…
- Excel Formula for Percentage Increase: Examples and TipsTo calculate percentage increase in Excel, subtract the old value from the new value, then divide by the…
- Excel Cell Value From List: Find or Select a MatchTo return a value from a list when you know a matching item, use XLOOKUP; with product IDs…
- Sumifs with date range?Learn how SUMIFS handles dates, boundaries, months, extra criteria, and common errors, with clear Excel examples to help…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.