just file name no path

  • Thread starter Thread starter musa.biralo
  • Start date Start date
M

musa.biralo

Hi
is there a way to get the file name only? Using this
fileToOpen = Application.GetOpenFilename("DBF Files (*.dbf), *.dbf")

i got complete path. i want the path as well as file name. So, for
path this is ok to me but not for the file name. Please help me or
direct me to the right place.

musa.biralo
 
Var1 = Application.GetOpenFilename("DBF Files (*.dbf), *.dbf")
fileToOpen = Right(Var1, Len(Var1) -
InStrRev(Var1,Application.PathSeparator))

Charles Chickering
 
If you're using xl2k or higher, you could use instrrev() to find the last \.

dim filetoopen as variant
dim JustFileName as string
fileToOpen = Application.GetOpenFilename("DBF Files (*.dbf), *.dbf")
if filetoopen = false then
exit sub
end if
justfilename = mid(filetoopen,instrrev(filetoopen,"\")+1)
 
If a serious question,
A MAC uses VBA5 and instrrev was introduced with VBA6. The mac is stuck
with the properties, methods and functions found in xl97 as far as VBA alone.
 
Thank you D_A_D

you just gave me what i was looking for...

thank you very much

musa.biralo
 
Just to add to Tom's response, I'd loop backwards.

dim iCtr as long
dim filetoopen as variant
dim JustFileName as string

fileToOpen = Application.GetOpenFilename("DBF Files (*.dbf), *.dbf")

if filetoopen = false then
exit sub
end if

for ictr = len(filetoopen) to 1 step -1
if mid(filetoopen, ictr, 1) = Application.PathSeparator then
justfilename = mid(filetoopen, ictr + 1)
exit for
end if
next ictr
 
Just thought I'd say thanks for this too. I've been looking all
morning for this!

Thanks :)
 
Back
Top