There are many situation while working in Excel that you need to get the name of the sheet. (Note – For formulas to work, the workbook must be saved at least once)
The formula to retrieve file name would be –
=CELL("filename",$A$1)
The formula to retrieve the sheet name would be –
=REPLACE(CELL("filename",$A$1),1,FIND("]",CELL("filename",$A$1)),"")
Note – CELL is a volatile function, hence this will calculated for every change in the sheet.
The formula to retrieve workbook name would be –
=REPLACE(LEFT(CELL("filename",$A$1),FIND("]",CELL("filename",$A$1))-1),1,FIND("[",CELL("filename",$A$1)),"")
Note – CELL is a volatile function. Hence, the formulas would recalculate every time, the worksheet changes.