To get only the workbook name (file name without the path or extension) in Excel, use the formula =REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),"") — this returns just the name, like SalesReport instead of C:\Users\Name\Documents\[SalesReport.xlsx]Sheet1. You can also use VBA with ActiveWorkbook.Name to get the name directly. This article explains both methods, how they work, and common pitfalls.
Formula
The core formula relies on Excel’s CELL function, which returns information about a cell. When you use CELL("filename"), it returns the full path of the workbook in the format: drive:\path\[workbookname.xlsx]sheetname. The formula then strips everything before and including the closing bracket ], leaving only the workbook name (without the extension).
In symbols: WorkbookName = REPLACE(CELL("filename"), 1, FIND("]", CELL("filename")), "")
- CELL(“filename”) – returns the full path string.
- FIND(“]”, …) – finds the position of the closing bracket.
- REPLACE(…, 1, position, “”) – removes characters from position 1 to the bracket.
The result is the workbook name without the file extension (e.g., .xlsx). If you want the extension too, use =MID(CELL("filename"), FIND("]",CELL("filename"))+1, LEN(CELL("filename"))).
Worked Example
Suppose your file is saved as C:\Users\Alex\Documents\Project.xlsx and you are on Sheet1.
CELL("filename")returnsC:\Users\Alex\Documents\[Project.xlsx]Sheet1.FIND("]", ...)finds the position of]— in this string, it is at character 38 (count the characters).REPLACE(..., 1, 38, "")removes the first 38 characters, leavingProject.xlsx.
So the formula outputs Project.xlsx. If you want just Project, wrap it with =SUBSTITUTE(REPLACE(...), ".xlsx", "") or use =LEFT(result, LEN(result)-5) for a 5-character extension.
When to Use This Formula
This formula is useful for:
- Creating dynamic headers or footers that show the file name.
- Building summary sheets that reference the source workbook name.
- Auditing or reporting where you need to display which file produced a report.
Note that CELL("filename") only works if the workbook has been saved at least once. If you use it on a new unsaved workbook, it returns an empty string or a path without a filename.
Common Mistakes and Pitfalls
- Forgetting to save the file – the formula returns nothing until you save.
- Using it on a sheet that isn’t active –
CELL("filename")always returns the path of the active sheet, not necessarily the sheet where the formula is. If you have multiple sheets, the result may change when you switch sheets. - File extension length varies –
.xlsxis 5 characters, but.xlsmis also 5,.xlsis 4. If you strip the extension manually, use a formula that handles variable lengths, like=LEFT(A1, FIND(".", A1)-1). - Path contains a closing bracket – extremely rare but possible if a folder name has
]. The formula would break. In that case, use VBA.
VBA Alternative
If you prefer VBA or need the name in a macro, use:
Sub GetWorkbookName()
MsgBox ActiveWorkbook.Name
End Sub
This returns the full filename with extension (e.g., Project.xlsx). To get just the base name, use Left(ActiveWorkbook.Name, InStrRev(ActiveWorkbook.Name, ".") - 1).
VBA is more reliable because it doesn’t depend on the active sheet and works even if the file hasn’t been saved (though ActiveWorkbook.Name will be something like Book1).
How to Choose Between Formula and VBA
- Use the formula if you need a dynamic result in a cell that updates when the file is renamed or moved. It’s also easier for non-macro users.
- Use VBA if you need the name in a macro, if the formula fails due to special characters, or if you need to loop through open workbooks.
For most users, the formula is sufficient and avoids enabling macros.
Frequently Asked Questions
Why does CELL(“filename”) return an empty string?
Because the workbook hasn’t been saved yet. Save the file once, and the formula will populate. If you’re working in a web browser version of Excel, this function may not work at all.
How do I get the file name without the extension?
Use =SUBSTITUTE(REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),""),".xlsx","") for .xlsx files. For a general solution that works with any extension, use =LEFT(REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),""),FIND(".",REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),""))-1).
Does this work in Google Sheets?
No. Google Sheets doesn’t have a CELL("filename") function. In Google Sheets, use =SUBSTITUTE(INFO("filename"),".xlsx","") but it returns the full path as well. Alternatively, use =MID(INFO("filename"), FIND("]",INFO("filename"))+1, LEN(INFO("filename"))) to get the name.
Can I get the workbook name in a cell without using a macro?
Yes, the formula method works without macros. Just ensure the file is saved and the formula is entered in any cell.
Why does the result change when I switch sheets?
Because CELL("filename") returns the path of the active sheet. If you have multiple sheets, the result may include the sheet name. To avoid this, use the formula that strips everything before the bracket, which removes the sheet name as well.
Related
Formula used
in t | Finish time | min | 50 | 0 in d | Distance | km | 10 | 0 | 100000 out pace | Average pace | min/km | t / d | 2 out speed | Average speed | km/h | d / (t / 60) | 2
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Increase Internal Memory Xiaomi Phones: How-To
- Nvidia Display Settings Are Not Available: Fixes
- Gmod Keeps Crashing? Fixes That Actually Work
- Net Code Analysis Workflow: A Reliable Setup Guide
- Satellite Internet Down: What to Do Now
- Audit an AI Agent’s Privacy Before Connecting Accounts