Solved

Macro to get file name and file path to a cell

Posted on 2011-09-16
4
335 Views
Last Modified: 2012-05-12
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
Comment
Question by:Petersburg1
4 Comments
 
LVL 33

Expert Comment

by:jppinto
ID: 36548828
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
 
LVL 17

Accepted Solution

by:
andrewssd3 earned 250 total points
ID: 36548829
=CELL("filename")

Open in new window


does this, but it includes the worksheet name as well - you could trim this off later.
0
 
LVL 92

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 250 total points
ID: 36548843
As long as the file has been saved:

=SUBSTITUTE(LEFT(CELL("filename"),FIND("]",CELL("filename"))-1),"[","")
0
 

Author Closing Comment

by:Petersburg1
ID: 36548877
Perfect! And so quick
thank you
Nils
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
COPY from excel to notepad 3 32
Automating Excel Weekly Report 13 50
Excel copy picture into Outlook email 7 42
NEED TO UPDATE DATA IN EXCEL 18 25
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now