Work anywhere from any device with Microsoft 365

Upgrade to Microsoft 365 to work anywhere with the latest features and updates.

Upgrade now

How can I get the file name to show up in a cell of the excel sheet?

For example, If i have a file named 2011-06 Household Budget.xlsx, it should say 2011-06 Household Budget in the selected cell?

 

Is this easily done?

 

Question Info


Last updated April 28, 2020 Views 9,854 Applies to:
Answer
Answer

You can use the CELL function to get the file and sheet names. CELL returns both the file name and sheet name in the format of "C:\Path[FileName.xlsx]SheetName". You can parse out the desired component from that string. So, to get the filename including the extensdion with

 

=MID(CELL("filename",A1),FIND("[",CELL("filename",A1))+1,FIND("]",CELL("filename",A1))-FIND("[",CELL("filename",A1))-1)

 

Include "filename" as shown. Do not substitute the actual file name. The reference to A1 can be to any cell on the worksheet. It doens't matter which cell.

 

To get the filename without the extension, use

 

=MID(CELL("filename",A1),FIND("[",CELL("filename",A1))+1,FIND(".",CELL("filename",A1),FIND("[",CELL("filename",A1))+1)-FIND("[",CELL("filename",A1))-1)

 

Cordially,
Chip Pearson
Excel MVP 1998 - 2014
Pearson Software Consulting, LLC
www.cpearson.com

21 people were helped by this reply

·

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.