![]() |
![]() |
|
|||||||
| 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 |
|
Guest
Posts: n/a
|
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. |
|
|
|
#2 |
|
Banned
Join Date: Feb 2002
Posts: 1,582
|
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*" |
|
|
|
|
|
#3 |
|
Banned
Join Date: Feb 2002
Posts: 1,582
|
This time witout HTML enabled
=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 ] |
|
|
|
|
|
#4 |
|
Guest
Posts: n/a
|
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. |
|
|
|
#5 |
|
Guest
Posts: n/a
|
alternatively, could you tell me how to find the last "" in a string which is a path.
|
|
|
|
#6 |
|
Banned
Join Date: Feb 2002
Posts: 1,582
|
Ignore the extra back slashes they just happen when you post the comment.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|