How to extract the path infor

G

Guest

Guest
I have a String variable folder, whose value could be "D:level1level2..sth"
I need to extract the "sth", how could i realise this? length of "sth" is not fixed.
Thx.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi

These things are generally easier if you do them first on a Worksheet, then adapt to VBA..

=MID(A1,SEARCH("\st*",A1)+2,LEN(A1))

Works on a Worksheet, so..

Dim strFile As String
strFile = "D:\level1\level2\..\sth"
strFile = _
Mid(strFile, WorksheetFunction.Search("\st*", strFile) + 2, Len(strFile))
MsgBox strFile

Will work in VBA. Of course you should be aware that it will get in wrong if there is a directory before/after it like "\sh*"
 
Upvote 0
This time witout HTML enabled :eek:)

=MID(A1,SEARCH("\st*",A1)+2,LEN(A1))

Works on a Worksheet, so..

Dim strFile As String
strFile = "D:\level1\level2\..\sth"
strFile = _
Mid(strFile, WorksheetFunction.Search("\st*", strFile) + 2, Len(strFile))
MsgBox strFile

Will work in VBA. Of course you should be aware that it will get in wrong if there is a directory before/after it like "\sh*"


_________________
Kind Regards
Dave Hawley
OzGrid Business Applications
Microsoft Excel/VBA Training
If it's Excel, then it's us!
This message was edited by Dave Hawley on 2002-03-06 21:31
 
Upvote 0
Sorry,i am not so clear about your codes:
Dim strFile As String
strFile = "D:\\level1\\level2\\..\\sth"
strFile = _
Mid(strFile, WorksheetFunction.Search("\\st*", strFile) + 2, Len(strFile))
MsgBox strFile

How come so many ""?
I need to extract the string after last ""?
Is this possible using simple codes?
Please enlighten.
 
Upvote 0
alternatively, could you tell me how to find the last "" in a string which is a path.
 
Upvote 0

Forum statistics

Threads
1,215,065
Messages
6,122,944
Members
449,095
Latest member
nmaske

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