Convert Shared folder path to UNC path

后端 未结 2 1677
名媛妹妹
名媛妹妹 2021-01-07 01:35

I\'m trying to convert current shared folder path to unc path by manipulating current path with computer name. However result in compile error: expected array on the line\"e

2条回答
  •  难免孤独
    2021-01-07 02:22

    Or use file system object:

    Function GetUNCLateBound(strMappedDrive As String) As String
    
        Dim objFso  As Object
        Set objFso = CreateObject("Scripting.FileSystemObject")
    
        Dim strDrive As String
        Dim strShare As String
    
        'Separate the mapped letter from
        'any following sub-folders
        strDrive = objFso.GetDriveName(strMappedDrive)
    
        'find the UNC share name from the mapped letter
        strShare = objFso.Drives(strDrive & "\").ShareName
    
        'The Replace function allows for sub-folders
        'of the mapped drive
        GetUNCLateBound = Replace(strMappedDrive, strDrive, strShare)
    
        Set objFso = Nothing 'Destroy the object
    
    End Function
    

    I just found and modified this, to which the credit is due, to be late-bound:

    http://pagecommunication.co.uk/2014/07/vba-to-convert-a-mapped-drive-letter-to-unc-path/

提交回复
热议问题