Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

VBA This - File location but not file

Posted on 2013-06-30
4
449 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 46

Expert Comment

by:Martin Liss
ID: 39288552
Dim intPos As Integer

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

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 46

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Excel Multi Sheet Formula 13 33
Set WorkSheet  not Working 9 42
Need help with Clear Macro 4 26
VBA working with shapes 6 11
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

829 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