Macro to get file name and file path to a cell

Dear Experts,
I'm looking for a function like =Now() which returns date/time into a cell. Same idea but I want as return the path and the file name like this: \\evofiles\jg library\12-Quality\2-Internal\3-Projects\Document Registration\Document_Registration_DRAFT.xlsm

Is there a ready command? Could such command be added as add in or macro?

As alternative variant but not as good would be just a macro which I can add to my quick access toolbar then..

thanks


Petersburg1Asked:
Who is Participating?
 
andrewssd3Connect With a Mentor Commented:
=CELL("filename")

Open in new window


does this, but it includes the worksheet name as well - you could trim this off later.
0
 
jppintoCommented:
Just insert a new module on your VBA editor and insert this custom function. Then on your sheet, just insert like this:

=FileName()

and you will get something like this:

D:\Experts_Exchange\FileName.xlsm

jppinto
Function FileName()
    FileName = ActiveWorkbook.FullName
End Function

Open in new window

0
 
Patrick MatthewsConnect With a Mentor Commented:
As long as the file has been saved:

=SUBSTITUTE(LEFT(CELL("filename"),FIND("]",CELL("filename"))-1),"[","")
0
 
Petersburg1Author Commented:
Perfect! And so quick
thank you
Nils
0
All Courses

From novice to tech pro — start learning today.