How to Get Workbook Name Only in Excel
Learn multiple Excel methods to get workbook name only with step-by-step examples, advanced techniques, and practical business applications.
How to Get Workbook Name Only in Excel
Why This Task Matters in Excel
When you build dashboards, reporting templates, or monthly models in Excel, you often need to display the workbook’s name without the full file path or sheet name. For instance, a template might populate a cover page that automatically shows the current file’s name so users always know which version they are looking at. Auditors frequently ask that every printed page include the file name in the footer; showing only the workbook name keeps the footer short and professional. Finance teams that consolidate files through Power Query or macros often use the workbook name as a unique identifier in logs, lookup tables, or error messages.
Another common scenario is referencing the workbook name inside formulas that build dynamic links to external files. Suppose you copy one month’s model folder to create next month’s set of workbooks. If the workbook name flows into formulas automatically, there is zero manual editing after you copy the file—a major time-saver. Operations groups also store daily production workbooks in a network folder. A summary workbook may extract the date portion of each file’s name (for example “Production_2023-09-27.xlsm”) to build a master schedule or to verify whether a file has already been processed.
Excel is uniquely suited to this task because it can interrogate its own metadata using the CELL function and can manipulate text with a rich toolset: LEFT, RIGHT, MID, SEARCH, FIND, LEN, TEXTAFTER, LET, and newer dynamic array functions. If you rely on another program to rename files, you introduce manual steps and potential errors. Mastering this technique therefore streamlines governance, reduces mistakes, and integrates seamlessly with existing Excel workflows such as formulas, VBA, and Power Query. Without it, analysts resort to hard-coding the workbook name in multiple places—an error-prone approach that breaks the moment the file is renamed or copied. Learning to pull the workbook name automatically is a foundational skill that sits at the intersection of text manipulation, dynamic references, and automation in Excel.
Best Excel Approach
For most users, the fastest, version-agnostic method combines the CELL function, which returns the full path of the current workbook, with text functions that strip out everything before the workbook name and everything after the file extension. The classic all-in-one formula is:
=LEFT(MID(CELL("filename",A1),FIND("[",CELL("filename",A1))+1,255), FIND("]",CELL("filename",A1)) - FIND("[",CELL("filename",A1)) -1)
Why this approach?
- CELL(\"filename\") works in every desktop version since Excel 2000.
- It updates automatically the moment you save a newly-named file.
- It needs no helper columns or VBA, so it is safe for locked workbooks or shared environments.
With Microsoft 365, you can streamline the logic using TEXTAFTER and TEXTBEFORE, making the formula shorter and easier to read:
=TEXTBEFORE(TEXTAFTER(CELL("filename"), "["),"]")
Prerequisites: the workbook must have been saved at least once because CELL(\"filename\") returns an empty string in unsaved workbooks. For dynamic arrays, no additional setup is required; older versions require CSE (Control + Shift + Enter) only if you wrap the formula inside other array processing functions.
The core logic flows like this:
- CELL(\"filename\") pulls something like \"C:\Finance\Budget[Forecast_Q2.xlsx]Summary\".
- FIND or TEXTAFTER locates the opening bracket [ which always precedes the workbook name.
- FIND or TEXTBEFORE locates the closing bracket ] which always follows the workbook name.
- MID, LEFT, or dynamic text functions slice out the characters between these brackets—precisely the workbook name without path or sheet.
Parameters and Inputs
CELL(\"filename\") takes two arguments:
- \"filename\" – a text literal requesting the file path metadata.
- reference – any cell reference, most commonly A1. The cell address does not affect the result, but including it avoids errors if you later enter the formula from another workbook.
Text functions require only standard text strings:
- start_num and num_chars (for MID) must be positive whole numbers.
- find_text and within_text (for FIND/SEARCH) are case sensitive for FIND and case insensitive for SEARCH.
- TEXTAFTER and TEXTBEFORE accept optional instance_num (which occurrence to consider) and match_mode (0 exact, 1 case-insensitive).
Data preparation: the workbook must be saved. If your file contains unusual characters, Excel still preserves them, but share-point URLs can exceed 255 characters; in such rare cases, the classic formula’s hard-coded 255 length in MID might truncate. Increase it to 1024 to be safe.
Edge cases:
- Unsaved workbooks return \"\" so downstream text functions will yield #VALUE errors.
- Workbooks saved with names containing \"]\" will break the logic because the bracket acts as a delimiter. Such names are rare and discouraged by Windows file-name rules, but network sync tools sometimes insert them. Use SUBSTITUTE to replace the closing bracket before parsing if needed.
Step-by-Step Examples
Example 1: Basic Scenario
Imagine you have just built \"Sales_Report.xlsx\" and want the report title in [B2] to reflect the workbook name automatically.
- Save the workbook once. Otherwise CELL(\"filename\") returns nothing.
- In cell [B2] type the simple 365 formula:
=TEXTBEFORE(TEXTAFTER(CELL("filename"), "["), "]")
- Press Enter. The cell displays Sales_Report.xlsx.
- Rename the file to Sales_Report_v2.xlsx and save. The value in [B2] updates instantly.
Why it works: TEXTAFTER grabs everything after the \"[\" character, producing \"Sales_Report.xlsx]Sheet1\". TEXTBEFORE then chops everything after \"]\", leaving only the workbook name.
Troubleshooting tips: If the formula shows a path, double-check you did not omit either TEXTAFTER or TEXTBEFORE. If you see #NAME?, you are on an older Excel version; switch to the classic LEFT/MID version. If the cell stays blank, save the workbook, then press F9 to recalculate.
Variations: You might want just the base name without extension. Wrap the result in TEXTBEFORE once more:
=TEXTBEFORE(TEXTBEFORE(TEXTAFTER(CELL("filename"), "["), "]"), ".")
This returns \"Sales_Report\".
Example 2: Real-World Application
A consulting firm stores each project’s deliverable in its own folder:
\"C:\Projects\ClientA[ProjectA_Presentation_v04.pptx]\" and
\"C:\Projects\ClientA[ProjectA_Model_v04.xlsx]\"
The financial model workbook needs to display its own name in a dashboard header and simultaneously feed the same name into a Power Query parameter so the query can locate supplementary CSV files that share the same stem.
- Open the model workbook.
- In a hidden ‘Config’ sheet, reserve cell [B5] for the workbook name. Enter:
=LET(
FullPath, CELL("filename",A1),
FileName, TEXTBEFORE(TEXTAFTER(FullPath,"["),"]"),
BaseName, TEXTBEFORE(FileName,"."),
BaseName
)
- The LET function stores intermediary results, making the formula readable and recalc efficient.
- Highlight [B5] and name it wbName via the Name Box.
- In Power Query, create a parameter called pqFileStem whose current value equals =Excel.CurrentWorkbook()[[Name=\"wbName\"]][Content][0][Column1]. This passes \"ProjectA_Model_v04\" into Power Query each time the workbook name changes.
Business impact: When the consultant versions the file to v05 or renames it for a new client, both the dashboard header and Power Query automatically update. There is no need to edit hard-coded paths in twenty queries—saving one oversight can avoid hours of debugging broken links.
Performance considerations: LET prevents repeated evaluation of CELL and TEXT functions, which is beneficial when hundreds of formulas reference wbName. In Excel 365 this approach is fully volatile but negligible in typical file sizes.
Example 3: Advanced Technique
Suppose an enterprise uses SharePoint and OneDrive where paths exceed 260 characters, and workbook names might embed dates, for example \"[ExecutiveSummary_2023-09-30.xlsm]\". They also employ strict naming conventions that forbid spaces and brackets but allow underscores and hyphens. You must derive three pieces: full workbook name, base name without extension, and the embedded date.
- Insert this advanced formula in [C3] (Excel 365):
=LET(
fp, CELL("filename"),
fn, TEXTBEFORE(TEXTAFTER(fp,"["),"]"), /* workbook name */
base, TEXTBEFORE(fn,"."), /* remove extension */
dtString, TEXTAFTER(base,"_"), /* isolate date */
dt, DATE(VALUE(LEFT(dtString,4)), VALUE(MID(dtString,6,2)), VALUE(RIGHT(dtString,2))), /* convert to real date */
HSTACK(fn, base, dt)
)
The formula spills three columns: \"ExecutiveSummary_2023-09-30.xlsm\", \"ExecutiveSummary_2023-09-30\", and 30-Sep-2023.
Advanced features used: LET for clarity, HSTACK to spill horizontally, and dynamic DATE parsing without helper columns.
Error handling: If the naming convention breaks (no underscore), TEXTAFTER returns #VALUE. Wrap it in IFERROR with a custom message \"Invalid file name format\".
Performance tips: Because CELL is volatile, the formula recalculates whenever anything changes. In large workbooks, store only fp in one cell and reference it in downstream formulas to avoid repeated calls.
Professional use: This technique feeds the extracted date into a timeline slicer, enabling the executive summary to adjust charts automatically based on the date embedded in the workbook’s name. No manual parameter entry is required.
Tips and Best Practices
- Always save the workbook once before testing. Unsaved files return blank paths.
- Store the workbook name result in one named cell (for example wbName). Link every other formula or VBA macro to this name to centralize maintenance.
- Use LET in modern Excel to improve readability, reduce volatility overhead, and document logic inline.
- Prefer TEXTAFTER/TEXTBEFORE functions in Microsoft 365—they are shorter, more readable, and don’t require nested LEN calculations.
- For legacy environments, test the classic LEFT-MID approach thoroughly and bump the MID length from 255 to 1024 if your file paths are extremely long.
- Protect key cells that hold the formula so users cannot overwrite them, especially in shared templates distributed company-wide.
Common Mistakes to Avoid
- Forgetting to save the file: CELL returns \"\" which causes #VALUE errors downstream. Always instruct users to save immediately after creating a new template.
- Omitting the second argument in CELL: Without a reference like A1, the function may refer to the active workbook when entered from another workbook, leading to misleading results.
- Using FIND instead of SEARCH when case sensitivity matters: FIND treats \"Workbook.xlsx\" and \"workbook.xlsx\" differently. If consistent casing is uncertain, switch to SEARCH.
- Hard-coding string lengths: People sometimes write LEFT(CELL(\"filename\"), 20). This breaks as soon as the file name length changes. Always calculate positions dynamically with FIND or TEXTBEFORE.
- Placing the formula in volatile heavy sheets without LET: Re-evaluating long nested formulas thousands of times slows performance. Store the result once and reference that cell elsewhere.
Alternative Methods
Although formulas cover 95% of use cases, other techniques may be preferable in certain environments.
| Method | Pros | Cons | Best for |
| (Formula) CELL + TEXT functions | Works in any Excel version, automatic update, no macros | Slightly complex formula, volatile | Standard workbooks, shared templates |
| VBA UDF (=MWorkbookName()) | Single clean function, can strip extension easily | Requires macro-enabled file, macro security prompts | Power users comfortable with VBA |
| Power Query | Returns workbook name via =Excel.CurrentWorkbook() quickly | Requires refresh, not live updating in worksheet cells | ETL dashboards, data models |
| Office Scripts (Excel for web) | Automates rename + capture | Currently limited adoption | Web-based automation scenarios |
| Static field in Footer/Header | No formula needed, prints automatically | Not visible in cell grid, no downstream use | Printed reports only |
VBA example:
Function MWorkbookName(Optional withoutExt As Boolean = False) As String
Dim nm As String
nm = ThisWorkbook.Name
If withoutExt Then nm = Left(nm, InStrRev(nm,".") - 1)
MWorkbookName = nm
End Function
Use =MWorkbookName(TRUE) to omit the extension.
When to switch methods: if your organization blocks macros, stay with formulas. If you already distribute macro-enabled files and want a cleaner worksheet, a UDF is elegant. For data mash-ups feeding Power BI, Power Query is natural because the workbook name often drives file-folder queries.
FAQ
When should I use this approach?
Use it whenever the workbook name needs to appear inside the workbook itself, whether as a label, part of a dynamic file path, or a parameter any other feature consumes. It is particularly valuable in templates that will be copied and renamed frequently.
Can this work across multiple sheets?
Yes. The CELL function returns the same full path regardless of the sheet from which it is called. You can place the formula on one hidden sheet and reference it from any other sheet without recalculating the logic multiple times.
What are the limitations?
The main limitation is that CELL(\"filename\") returns an empty string in unsaved workbooks. Extremely long SharePoint URLs may exceed the length assumption in classic MID formulas, so increase the character limit. Also, if the workbook name contains \"]\" the parsing breaks; avoid unusual characters in file names.
How do I handle errors?
Wrap parsing steps in IFERROR. For example:
=IFERROR(TEXTBEFORE(TEXTAFTER(CELL("filename"),"["),"]"),"Workbook not saved")
This displays a friendly message instead of #VALUE errors in unsaved files or unexpected name formats.
Does this work in older Excel versions?
Yes. The classic LEFT-MID-FIND formula works back to Excel 2000. TEXTAFTER and TEXTBEFORE require Microsoft 365. LET, HSTACK, and dynamic arrays also require 365. For legacy installations, stick with the longer formula and avoid functions introduced after 2016.
What about performance with large datasets?
The CELL function is volatile, so it recalculates whenever anything changes. However, if you evaluate it once and refer to that cell elsewhere, the hit is negligible. Avoid embedding the logic in thousands of rows. LET further optimizes by storing intermediate results instead of recalculating each segment.
Conclusion
Knowing how to extract the workbook name automatically is a small skill with outsized benefits. It keeps templates self-aware, reduces manual edits after renaming, and provides clean identifiers for automation tools like Power Query and VBA. Whether you rely on the classic LEFT-MID technique for backward compatibility or embrace modern TEXTAFTER and LET functions, you now have the knowledge to implement robust, version-proof solutions. Apply the examples, adapt them to your organization’s standards, and integrate the result into dashboards, headers, or any place metadata adds clarity. Master this technique and you strengthen your overall Excel automation toolkit—paving the way for more dynamic, error-free workbooks.
Related Articles
How to Show the 10 Most Common Text Values in Excel
Learn multiple Excel methods to list the 10 most frequent text values—complete with step-by-step examples, business use cases, and expert tips.
How to Abbreviate Names Or Words in Excel
Learn multiple Excel methods to abbreviate names or words with step-by-step examples and practical applications.
How to Abbreviate State Names in Excel
Learn multiple Excel methods to abbreviate state names with step-by-step examples, professional tips, and real-world applications.