Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Function to return filepath given full filename

I need a function (whether built in or user defined) that can return the filepath (ie C:\mypath ) given the full filename with path ( as returned in the GetOpenFileName function, ie C:\mypath\myfile.xls )

Any help would be greatly appreciated

Matt Lawso


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Function to return filepath given full filename

ANy suggestions to improve this function

(I thought about it for a while and came up with a solution

Function ReturnPath(sFname
Dim spath As String, i As Long, leng As Intege
leng = Len(sFname
For i = 1 To leng -
If Mid(sFname, leng - i, 1) = "\" The
spath = Mid(sFname, 1, leng - i - 1
Exit Fo
End I
Nex

ReturnPath = spat

End Function
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Function to return filepath given full filename

Public Function sPath(sStr As String)
If InStr(sStr, "\") = 0 Then
sPath = ""
Else
i = Len(sStr)
Do While i 0
If Mid(sStr, i, 1) = "\" Then
sPath = Left(sStr, i )
Exit Do
End If
i = i - 1
Loop
End If
End Function


If you have excel 2000 or later, you can use split to get the filename
sStr = "C:\Myfolder1\myfolder2\myfile.xls"
v = (sStr,"\")
sPath = Left(sStr,len(sStr)-v(ubound(v)))

--
Regards,
Tom Ogilvy




"Matt Lawson" wrote in message
...
I need a function (whether built in or user defined) that can return the

filepath (ie C:\mypath ) given the full filename with path ( as returned in
the GetOpenFileName function, ie C:\mypath\myfile.xls ).

Any help would be greatly appreciated,

Matt Lawson




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 733
Default Function to return filepath given full filename

"Tom Ogilvy" wrote...
....
If you have excel 2000 or later, you can use split to get the filename
sStr = "C:\Myfolder1\myfolder2\myfile.xls"
v = (sStr,"\")
sPath = Left(sStr,len(sStr)-v(ubound(v)))

....

If OP has XL2K or later, OP could use InStrRev.

p = InStrRev(sStr, "\")
sPath = IIf(p 0, Mid(sStr, p + 1), "")


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Function to return filepath given full filename

Excellent suggestion - but as written that gives the filename. For the path
I think you meant:

p = InStrRev(sStr, "\")
sPath = IIf(p 0, Left(sStr, p), "")


--
Regards,
Tom Ogilvy

"Harlan Grove" wrote in message
...
"Tom Ogilvy" wrote...
...
If you have excel 2000 or later, you can use split to get the filename
sStr = "C:\Myfolder1\myfolder2\myfile.xls"
v = (sStr,"\")
sPath = Left(sStr,len(sStr)-v(ubound(v)))

...

If OP has XL2K or later, OP could use InStrRev.

p = InStrRev(sStr, "\")
sPath = IIf(p 0, Mid(sStr, p + 1), "")






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Function to return filepath given full filename

Just a correction of typos:

Dim v As Variant
sStr = "C:\Myfolder1\myfolder2\myfile.xls"
v = Split(sStr, "\")
sPath = Left(sStr, Len(sStr) - Len(v(UBound(v))))
'MsgBox sPath



Tom Ogilvy wrote:

Public Function sPath(sStr As String)
If InStr(sStr, "\") = 0 Then
sPath = ""
Else
i = Len(sStr)
Do While i 0
If Mid(sStr, i, 1) = "\" Then
sPath = Left(sStr, i )
Exit Do
End If
i = i - 1
Loop
End If
End Function

If you have excel 2000 or later, you can use split to get the filename
sStr = "C:\Myfolder1\myfolder2\myfile.xls"
v = (sStr,"\")
sPath = Left(sStr,len(sStr)-v(ubound(v)))

--
Regards,
Tom Ogilvy

"Matt Lawson" wrote in message
...
I need a function (whether built in or user defined) that can return the

filepath (ie C:\mypath ) given the full filename with path ( as returned in
the GetOpenFileName function, ie C:\mypath\myfile.xls ).

Any help would be greatly appreciated,

Matt Lawson



--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Function to return filepath given full filename

Bunch of typos on that - guess I shouldn't attempt an xl2000 solution if I
only have xl97 on that machine <g. Thanks for the correction.

--
Regards,
Tom Ogilvy

"Dave Peterson" wrote in message
...
Just a correction of typos:

Dim v As Variant
sStr = "C:\Myfolder1\myfolder2\myfile.xls"
v = Split(sStr, "\")
sPath = Left(sStr, Len(sStr) - Len(v(UBound(v))))
'MsgBox sPath



Tom Ogilvy wrote:

Public Function sPath(sStr As String)
If InStr(sStr, "\") = 0 Then
sPath = ""
Else
i = Len(sStr)
Do While i 0
If Mid(sStr, i, 1) = "\" Then
sPath = Left(sStr, i )
Exit Do
End If
i = i - 1
Loop
End If
End Function

If you have excel 2000 or later, you can use split to get the filename
sStr = "C:\Myfolder1\myfolder2\myfile.xls"
v = (sStr,"\")
sPath = Left(sStr,len(sStr)-v(ubound(v)))

--
Regards,
Tom Ogilvy

"Matt Lawson" wrote in message
...
I need a function (whether built in or user defined) that can return

the
filepath (ie C:\mypath ) given the full filename with path ( as returned

in
the GetOpenFileName function, ie C:\mypath\myfile.xls ).

Any help would be greatly appreciated,

Matt Lawson



--

Dave Peterson



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Function to return filepath given full filename

Doesn't stop me for posting xl97 solutions, er, suggestions with only xl2002
available <vvbg.

Tom Ogilvy wrote:

Bunch of typos on that - guess I shouldn't attempt an xl2000 solution if I
only have xl97 on that machine <g. Thanks for the correction.

--
Regards,
Tom Ogilvy


<<snipped


--

Dave Peterson

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Function to return filepath given full filename

Try:

Left(FullFileName, Len(FullFileName)-Len(Dir(FullFileName)) - 1)

Assumes this is an existing file on the user's computer.

(Credit to Ivan F. Moala!)


--

Vasant





"Matt Lawson" wrote in message
...
I need a function (whether built in or user defined) that can return the

filepath (ie C:\mypath ) given the full filename with path ( as returned in
the GetOpenFileName function, ie C:\mypath\myfile.xls ).

Any help would be greatly appreciated,

Matt Lawson




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to return to full worksheet after filtering a colume? tbear Excel Discussion (Misc queries) 3 March 8th 10 09:47 PM
Filename extract from Filepath Text String DaveyC Excel Discussion (Misc queries) 4 December 20th 07 04:04 PM
Prevent Excel putting full filename in external links on update [email protected] Excel Discussion (Misc queries) 5 March 29th 07 08:42 PM
Filepath Marie-Jo Excel Discussion (Misc queries) 3 July 5th 05 07:56 PM
get filename and filepath Robert Ehrlich Excel Programming 3 December 21st 03 12:23 PM


All times are GMT +1. The time now is 08:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"