Thanks Thanks:  0
Likes Likes:  0
Results 1 to 6 of 6

Thread: How to extract the path infor

  1. #1
    Guest

    Default

    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. #2
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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. #3
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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. #4
    Guest

    Default

    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. #5
    Guest

    Default

    alternatively, could you tell me how to find the last "" in a string which is a path.

  6. #6
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Ignore the extra back slashes they just happen when you post the comment.

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •