To get only the folder path of an Excel workbook (without the file name), use =LEFT(CELL("filename"),FIND("[",CELL("filename"))-1) in any cell. This returns the full directory path ending with a backslash, such as C:\Users\Name\Documents\. Below are five methods, including built-in functions, VBA, and a quick copy trick, with step-by-step instructions and common pitfalls.
Why You Need the Workbook Path Alone
Excel’s CELL("filename") function returns the full path, workbook name, and sheet name all together, like C:\Users\Name\Documents\Book1.xlsx\Sheet1. When you need to reference a folder in a formula, link to a file, or build a dynamic path, you usually want just the directory part. Extracting that cleanly avoids errors in formulas and makes your spreadsheets more portable.
Method 1: Formula with CELL, FIND, and LEFT
The most common formula-based approach uses three functions:
CELL("filename")– returns the full path in the formatdrive:\path\[workbook.xlsx]sheet.FIND("[", ...)– locates the position of the opening square bracket, which marks the start of the workbook name.LEFT(..., position-1)– extracts everything before that bracket.
Enter this in any cell (e.g., A1):
=LEFT(CELL("filename"),FIND("[",CELL("filename"))-1)
If the workbook is saved as C:\Reports\2025\Sales.xlsx, the formula returns C:\Reports\2025\. Note that the trailing backslash is included. If you need the path without the final backslash, wrap it with =LEFT(... , LEN(...)-1).
Method 2: Using SUBSTITUTE to Remove the File Name
An alternative formula uses SUBSTITUTE to replace the file name with nothing. This is useful when you already have the full path in a cell (e.g., from CELL("filename") in A1):
=SUBSTITUTE(A1, MID(A1, FIND("[",A1), FIND("]",A1)-FIND("[",A1)+1), "")
This removes the bracketed part (including the brackets), leaving only the folder path. It’s more verbose but easier to adapt if you need to modify the file name portion.
Method 3: VBA Custom Function
If you use macros frequently, a small user-defined function (UDF) can return the path instantly. Press Alt+F11 to open the VBA editor, insert a new module, and paste:
Function GetPathOnly() As String
GetPathOnly = ThisWorkbook.Path & "\"
End Function
Now in any cell, type =GetPathOnly() and it returns the folder path. This method works even if the workbook is unsaved (it returns an empty string). To get the path of the workbook that contains the formula (not necessarily the active one), use Application.ThisWorkbook.Path instead.
Method 4: Copy Path from File Explorer
If you only need the path once (for a hyperlink or reference), the fastest way is to use Windows File Explorer:
- Open the folder where the workbook is saved.
- Click on the address bar (or press Ctrl+L).
- The full path appears as text; copy it with Ctrl+C.
- Paste it into Excel. It will not include a trailing backslash, which is fine for most uses.
On macOS, right-click the file in Finder and hold Option to see “Copy as Pathname”.
Method 5: Using Power Query (Get & Transform)
For advanced users, Power Query can extract the path from the current workbook:
- Go to Data tab > Get Data > From File > From Workbook.
- In the Navigator, select the current workbook. It will show a query with a column named “Folder Path”.
- Load that column to a cell, or use it as a parameter.
This method is overkill for a single cell but useful when building a dynamic file-listing dashboard.
Common Problems and Fixes
- #VALUE! error – The workbook must be saved at least once for
CELL("filename")to work. Save the file and recalculate (F9). - Trailing backslash – If you don’t want it, use
=LEFT(A1,LEN(A1)-1)after getting the path. - Path changes when file is moved – Formulas using
CELLupdate automatically when the file is saved in a new location, but VBA’sThisWorkbook.Pathalways reflects the current location. - OneDrive/SharePoint paths – These may return a URL-like path (e.g.,
https://...) instead of a local drive. The formulas still work, but the path may not be usable in all Windows commands. - Sheet name in the result – The
CELLfunction includes the sheet name after the bracket. The formulas above remove it because they stop at the opening bracket.
Which Method Should You Choose?
For a one-time need, the File Explorer copy is simplest. For a dynamic formula that updates when the file moves, use the LEFT/FIND formula. If you already use VBA for other tasks, the custom function is clean and reusable. Power Query is best when you’re already building a data pipeline. Avoid using CELL in array formulas or across multiple sheets, as it only returns the path of the sheet that recalculates first.
Frequently Asked Questions
Why does CELL(“filename”) return an empty string?
This happens when the workbook has never been saved. Save the file once (even to a temporary location) and the function will return the full path. If you’re using Excel Online, this function may not be supported – use File > Info > Copy Path instead.
Can I get the path without the trailing backslash?
Yes. After extracting the path with any method, strip the last character with =LEFT(A1, LEN(A1)-1) if the path ends with a backslash. Be careful if the path is the root of a drive (e.g., C:\) – removing the backslash would give C:, which is not a valid folder path.
Does this work in Google Sheets?
No. Google Sheets has no direct equivalent to CELL("filename"). You can get the file name via =SUBSTITUTE(INFO("DIRECTORY"),"\","/") but it returns the directory of the Sheets file, not the full path. For a true path, use Google Apps Script with DriveApp.getFileById().
How do I get the path of a different open workbook?
The CELL formula always returns the path of the workbook that contains the formula. To get another workbook’s path, use VBA: Workbooks("Other.xlsx").Path. Or, if you have a cell in that workbook with CELL("filename"), you can reference it cross-workbook.
Will the formula break if I rename the file?
No. The formula recalculates when the workbook is saved, so it will automatically return the new path. If you rename the file while it’s open, Excel may prompt you to save; after saving, the formula updates.
Is there a way to get the path in a macro without saving?
No. Excel does not store a path for unsaved workbooks. In VBA, ThisWorkbook.Path returns an empty string if the workbook has never been saved. You must save the file at least once before you can retrieve its path.
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
- Campus Tech Innovation Hubs: What They Are
- Poco C51 Airtel Prepaid Locked Variant India?
- Jenkins vs GitHub Actions: Which CI/CD Fits Your Team?
- Turn Off Backup Encryption in iTunes?
- Shared VPS Hosting: Is It Better?
- Disk Defrag Pro: What It Does and Whether You Need It