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?

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

24 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

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

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated February 10, 2024 Views 10,948 Applies to: