extract path from FullName

J

Judy Ward

I have this working, but would like to know if there is a way to do this
without using my tempDir variable (just can't wrap my head around this!).

The goal is to strip off the filename and one folder name. Here is what I
am using:
fullPath = ActiveWorkbook.FullName
tempDir = Left(fullPath, InStrRev(fullPath, "\") - 1)
exportDir = Left(fullPath, InStrRev(fullPath, "\") - 1)

Can this be done without tempDir?

Thank you,
Judy
 
R

Rick Rothstein

Yes, mainly because your code is not making use of the tempDir variable.
 
J

Judy Ward

I'm sorry. Please pardon the typo, was trying to include only the applicable
lines and not all of my code.

The code below should have been:
fullPath = ActiveWorkbook.FullName
tempDir = Left(fullPath, InStrRev(fullPath, "\") - 1)
exportDir = Left(tempDir, InStrRev(tempDir, "\"))

If I say I'm sorry can I still get some help with this?

Thank you,
Judy
 
R

Rick Rothstein

To answer your question, you can eliminate the tempDir variable; but, to do
so, you would have to substitute what it is equal to twice in your last line
(once for each appearance). The code is probably clearer if you leave it as
it. With that said, the point Dave raised is what you should follow.
Application.Path gives you want you want directly...

exportDir = Application.Path
 

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