![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
|
Hi everyone,
Ive looked on the board and found similar problems, but nothing that quite matches mine. Im trying to find just the file name (no extension) from a directory returned from a macro. So for example, from the directory: s:FileServerFilesYear2002 |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
|
Hi,
Not sure about the worksheet function (would have imagined some sort of array formula) but you can use VBA like this:- Code:
Sub Test()
Dim strFullPath As String, strFileName As String
Dim lngCharLoop As Long
strFullPath = "s:FileServerFilesYear20023-02Jones, Rob.xls"
For lngCharLoop = Len(strFullPath) To 1 Step -1
If Mid$(strFullPath, lngCharLoop, 1) = "" Then Exit For
Next lngCharLoop
strFileName = Right(strFullPath, Len(strFullPath) - lngCharLoop)
MsgBox strFileName
End Sub
D |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Posts: 3,065
|
=MID(CELL("filename"),FIND("]",CELL("filename"))+1,255)
__________________
Free Excel based Web Toolbar available here. Jack in the UK J & R Excel Solutions "making Excel work for you" |
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: The Hague
Posts: 50,317
|
[quote]
On 2002-03-23 12:12, robfo0 wrote: Hi everyone, Ive looked on the board and found similar problems, but nothing that quite matches mine. Im trying to find just the file name (no extension) from a directory returned from a macro. So for example, from the directory: s:FileServerFilesYear2002 |
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
|
thanks guys!
|
|
|
|
|
|
#6 |
|
MrExcel MVP
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
|
[quote]
On 2002-03-23 12:12, robfo0 wrote: Hi everyone, Ive looked on the board and found similar problems, but nothing that quite matches mine. Im trying to find just the file name (no extension) from a directory returned from a macro. So for example, from the directory: s:FileServerFilesYear2002 |
|
|
|
|
|
#7 |
|
Board Regular
Join Date: Feb 2002
Location: Guderup, Denmark
Posts: 287
|
Hi
This code can also do the job: Function NameFromPath(strPath As String) As String Dim lngPos As Long Dim strPart As String lngPos = InStrRev(strPath, "") + 1 If lngPos > 0 Then strPart = Mid(strPath, lngPos, Len(strPath) - lngPos - 3) NameFromPath = strPart End Function regards Tommy |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|