Between Function?

robfo0

Active Member
Joined
Feb 19, 2002
Messages
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
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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

Hope it helps,
D
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,513
Messages
6,114,064
Members
448,545
Latest member
kj9

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top