VBA This - File location but not file

Hello,

I have a variable that stores a file path like this

fileLoc = "C:\Here\There\myFile.xls"

Now what splitting or anything I need to do to parse out the file name out of that string and retrun me only string without the filename like this

filLoc now becomes   "C:\Here\There"


what to do in VBA? if I want the strign like this from a full file path...

Thanks
RayneAsked:
Who is Participating?
 
Martin LissConnect With a Mentor Older than dirtCommented:
Or if you like one-line code

MsgBox Left(fileLoc, InStrRev(fileLoc, "\") - 1)
0
 
Martin LissOlder than dirtCommented:
Dim intPos As Integer

intPos = InStrRev(fileLoc, "\")
MsgBox Left(fileLoc, intPos - 1)
0
 
RayneAuthor Commented:
Thank you Martin, that works Gold :)
0
 
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0
All Courses

From novice to tech pro — start learning today.