Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract the filename from the path using Excel VBA 3

Status
Not open for further replies.

Moreco

Technical User
Jul 21, 2008
18
US
Hi,

I would like to extract the filename from the path using excel vba. As I open my file I store its name on a variable calle FileVar. I did some research and found an example of deleting the filename from the path using:
Code:
Directory = Left(VarFile, InStrRev(VarFile, "\"))
.

I am not sure how the above code works, but I need the opposite that the above code is giving me. I need the filename and its extension. Sorry for the simple question, but I couldn't find anything else on the web to help me understand.

Thanks in advance for any help.
 
Take a look at thread707-1493090 and replace

FilePath = "\\192.168.0.11\letters\mytiffile001.tif"
with
FileVar ="C:\bla\blabla\filename.ext"

There are a few different axamples on the thread

sam

 
You might also consider using the FileSystemObject
Code:
Set fs = CreateObject("Scripting.FileSystemObject")
fname=fs.GetFileName(VarFile)

_________________
Bob Rashkin
 
Directory = Left(VarFile, InStrRev(VarFile, "\"))
FileName = Mid(VarFile, 1 + InStrRev(VarFile, "\"))

Another (simpler) way:
FileName = Dir(VarFile)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you all so much!!!! Mission accomplished!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top