How can I show the current file name in a cell.

P

Patrick

How do you get excel to return the name of the current workbook into a
certain cell.
I can get the directory name by typing =Info("directory"), but I cannot get
the filename.
Is there a function that will return the current file name.

Thanks
 
T

T. Valko

Try one of these** :

This will return the full path including the sheet name:

=CELL("filename",A1)

Result will be something like: C:\TV\[Sheet name.xls]Sheet1

This will return just the file name including the file extension:

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

Result will be something like: Sheet name.xls

** the file must already exist. In other words, it must have been saved at
least once and given a file name.
 
H

Héctor Miguel

hi, Patrick !
How do you get excel to return the name of the current workbook into a certain cell.
I can get the directory name by typing =Info("directory"), but I cannot get the filename.
Is there a function that will return the current file name.

for the current (and saved) workbook...

path: =left(cell("filename"),find("[",cell("filename"))-2)
name: =mid(cell("filename"),find("[",cell("filename"))+1,find("]",cell("filename"))-find("[",cell("filename"))-5)
sheet: =mid(cell("filename"),search("]",cell("filename"))+1,now())

when the workbook has only one sheet names same as the workbook...
sheet: =mid(cell("filename"),if(iserror(find("]",cell("filename"))),lookup(2,1/(mid(cell("filename"),row($1:$255),1)="\"),row($1:$255))+1,find("]",cell("filename"))+1),31)

hth,
hector.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top