A Formula To Return a Path, Filename and Sheet Name in Excel

Handy Excel formulas to know

As you know, if you want the sheet name to appear on your printed report you can add it to the header or footer through File, Page Setup in Excel 2003 or Page Layout, Page Setup group in Excel 2007. It will print but it won't actually be in your worksheet.

If you want your spreadsheet's sheet name, filename or path to appear on your worksheet you can either type it into a cell or you can be smart and use the following formulas to dynamically show the info directly on your worksheet.

The following examples assume that the formulas are used in... F:\Excel\[Formula Samples.xls]Sheet1

Full path, file and sheet name: Formula: =CELL("filename",A1) Result: F:\Excel\[Formula Samples.xls]Sheet1

Filename only: Formula: =MID(CELL("filename",A1),FIND("[",CELL("filename",A1))+1, FIND("]",CELL("filename",A1))-FIND("[",CELL("filename",A1))-1) Result: Formula Samples.xls

Path only: Formula: =LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1),1)-1) Result: F:\Excel\

Sheet name only: Formula: =RIGHT(CELL("filename",A1),LEN(CELL("filename",A1))- FIND("]",CELL("filename",A1),1)) Result: Sheet1

Rather than try to retype these formulas, you can select each of them above and copy them into your Formula Bar in Excel.

P.S. Note that these formulas won't work if your sheet is named Book1 or if your workbook is new and hasn't been saved. These formulas won't work in versions prior to Excel 2000.

Website: This is just one of hundreds of Microsoft Excel tips available at www.TheExcelAddict.com?link=hubpages that will save you a significant amount of time.

by Francis Hayes (The Excel Addict)

Comments 9 comments

Raymond Trempe 7 years ago

How do I pick what I need form this total name like

C:\Users\My name\Documents\A-91 files\2008 information\2009-04-27 files\details.xlsx finaldocument

From 8 part, how do I use only the last 4 or the last 5 etc..

TheExcelAddict profile image

TheExcelAddict 7 years ago Author

I don't understand what you mean by "From 8 part, how do I use only the last 4 or the last 5 etc."

Al 7 years ago

Very nice. The formula for displaying the sheetname is exactly what I needed.

I'd like to understand the formula you've assembled but I get lost trying to decipher it with Excel's help.

Could you break this down for me?

Thanks in advance.

JFW 6 years ago

Very helpful. Your explanation answers the what, why and how questions that vex so many Excel users. Thank you and keep up the great work.

CHRIS 4 years ago

very helpful, francis, many thanks

Ray 4 years ago

In the Sheet name only: Formula: I have 4 words in the tab area Name Word1 Word2 Word3 how would I shorten the results to just the Name?

Dinesh Kumar 4 years ago

Thanks, Its very useful for me

martellawintek 4 years ago

hi there kevin sorry mate i`v took so long here is there contact

filling address , they have a wealth of knowledge , mention m wintekstold you to ring him

naveen 2 years ago

when i am using filename function in excel 1 (this is the filename) , and then i open excel 2, the cell in excel 1 changes from "excel 1" to "excel 2".

Please advise, how to prevent this.

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.

    More by this Author

    Click to Rate This Article