Consulting

Results 1 to 6 of 6

Thread: Solved: Code that returns the full path of a link

  1. #1
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    262
    Location

    Solved: Code that returns the full path of a link

    Hi

    Is there a way of taking a folder path:
    G:\folder

    and finding the full path, for example:
    \\server\sup\folder


    Thanks a lot

  2. #2
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    See this link:
    http://www.dailydoseofexcel.com/arch...mapped-drives/
    Let us know if it helps you.
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

  3. #3
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    262
    Location
    Thanks, this does work if the drive letter is upper case.

    Can it be made case insensitive, I have tried including some Ucase() functions so far.

    [VBA]'Switch on Windows Script Host Object Model in the Visual Basic Editor references

    Public Function ConvertMapped(ByVal sPath As String) As String

    Dim wsNet As WshNetwork
    Dim wsDrives As WshCollection
    Dim i As Long
    Dim sReturn As String

    Set wsNet = New WshNetwork
    Set wsDrives = wsNet.EnumNetworkDrives

    sReturn = sPath

    For i = 0 To wsDrives.Count - 1
    If Left$(sPath, 2) = wsDrives.Item(i) Then
    sReturn = Replace(sPath, wsDrives.Item(i), wsDrives.Item(i + 1), 1, 1)
    Exit For
    End If
    Next i

    ConvertMapped = sReturn

    End Function
    [/VBA]

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    [VBA] If LCase(Left$(sPath, 2)) = LCase(wsDrives.Item(i)) Then[/VBA]

  5. #5
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    262
    Location
    Thanks, I've now tried that with LCase and UCase but

    Z:\ returns the full path and

    z:\ just returns "z:\"

  6. #6
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    262
    Location
    I've made sure that the path going in to the function is uppercase by making both instances of sPath uppercase.

    [VBA]'Switch on Windows Script Host Object Model in the Visual Basic Editor references

    Public Function ConvertMapped(ByVal sPath As String) As String

    Dim wsNet As WshNetwork
    Dim wsDrives As WshCollection
    Dim i As Long
    Dim sReturn As String
    Dim sUpperPath As String

    Set wsNet = New WshNetwork
    Set wsDrives = wsNet.EnumNetworkDrives

    sUpperPath = UCase(sPath)
    sReturn = sUpperPath

    For i = 0 To wsDrives.Count - 1
    If Left$(sUpperPath, 2) = wsDrives.Item(i) Then
    sReturn = Replace(sUpperPath, wsDrives.Item(i), wsDrives.Item(i + 1), 1, 1)
    Exit For
    End If
    Next i

    ConvertMapped = sReturn

    End Function[/VBA]

    Thanks for help all.
    Last edited by sassora; 06-24-2012 at 01:50 AM.

Posting Permissions

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