[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

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
0
Rayne
Asked:
Rayne
  • 3
1 Solution
 
Martin LissRetired ProgrammerCommented:
Dim intPos As Integer

intPos = InStrRev(fileLoc, "\")
MsgBox Left(fileLoc, intPos - 1)
0
 
Martin LissRetired ProgrammerCommented:
Or if you like one-line code

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

Marty - MVP 2009 to 2013
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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