splitting file name and path

T

Tony Logan

In a macro I've written I need to get the filename and path names separately.
I was able to cheat a bit with the VBA coding becaue the filename will always
be the same...only the path will change. However, I'm wondering how to make
this code more flexible so I could also account for file names of different
sizes.

For example, right now I know I'll always be dealing with a file called
text01.doc. I know there are ten characters in the file name, so in the
following line of code, I count backwards 10 characters to get just the path:

sPathOnly = Left(sPathAndFilename, Len(sPathAndFilename) - 10)

Would there be a way to rewrite the code so that I can get the path only, no
matter the length of the filename? For instance, something that would read
everything up to the last slash, no matter if the path and filename were

C:\Work\folder1\test01.doc

or

C:\Work\folder1\some_extremely_long_filename.doc

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top