Solved

VBA This - File location but not file

Posted on 2013-06-30
4
424 Views
Last Modified: 2013-06-30
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
Comment
Question by:Rayne
  • 3
4 Comments
 
LVL 45

Expert Comment

by:Martin Liss
ID: 39288552
Dim intPos As Integer

intPos = InStrRev(fileLoc, "\")
MsgBox Left(fileLoc, intPos - 1)
0
 
LVL 45

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 39288554
Or if you like one-line code

MsgBox Left(fileLoc, InStrRev(fileLoc, "\") - 1)
0
 

Author Comment

by:Rayne
ID: 39288563
Thank you Martin, that works Gold :)
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 39288565
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

747 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

9 Experts available now in Live!

Get 1:1 Help Now