View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1811_] Rick Rothstein \(MVP - VB\)[_1811_] is offline
external usenet poster
 
Posts: 1
Default Use Dir() to fill out missing components from Path?

You can use the CurDir function to see what the current directory is. For
example...

MsgBox "You are trying to access " & CurDir & "\" & UserEnteredFileName

Rick


"Dan Williams" wrote in message
...
I’d like a way to flesh out a file’s path the way the Dir() function
does. The Dir() function (like the DIR command in DOS) fills in
missing components depending on what the current Path is set to.

Suppose the current Path is

C:\BigFolder

Then all of the following

Dir(“SubFolder\myfile.xls”)
Dir(“C:SubFolder\myfile.xls”)
Dir(“C:\BigFolder\SubFolder\myfile.xls”)

....will be treated as attempts to find this file:

C:\BigFolder\SubFolder\myfile.xls

If the User enters any one of the above strings, I’d like to tell
them:

You are trying to access C:\BigFolder\SubFolder\myfile.xls

And if they just enter the string “OtherFile.xls”, I’d like to respond
with:

You are trying to access C:\BigFolder\OtherFile.xls

....etc. I’d like to be able to make the responses WHETHER THE FILE
EXISTS OR NOT, so that if the file does NOT exist, my error message
can include the whole attempted path.

Is there some easy way I haven’t thought of to do this? I’m guessing
you’d have to treat all these cases separately. Or does someone have
an already-written routine that would do this?

Dan Williams
danwPlanet