Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

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


0
Petersburg1
Asked:
Petersburg1
2 Solutions
 
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
 
andrewssd3Commented:
=CELL("filename")

Open in new window


does this, but it includes the worksheet name as well - you could trim this off later.
0
 
Patrick MatthewsCommented:
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now