Option Explicit

'// 32-bit Function version.
'// Note:
Declare Function WNetGetConnection32 Lib "mpr.dll" _
Alias "WNetGetConnectionA" ( _
ByVal lpszLocalName As String, _
ByVal lpszRemoteName As String, _
lSize As Long) As Long

'// 32-bit declarations:
Dim lpszRemoteName As String
Dim lSize As Long

'// Use for the return value of WNetGetConnection() API.
Const NO_ERROR As Long = 0

'// The size used for the string buffer. Adjust this if you
'// need a larger buffer.
Const lBUFFER_SIZE As Long = 255

Function UNCPath(sDriveLetter As String)
'// Takes specified Local Drive Letter
'// eg E,D,H Etc and converts to UNC

Dim cbRemoteName As Long
Dim lStatus As Long

'// Add a colon to the drive letter entered.
sDriveLetter = sDriveLetter & ":"

'// Specifies the size in charaters of the buffer.
cbRemoteName = lBUFFER_SIZE

'// Prepare a string variable by padding spaces.
lpszRemoteName = lpszRemoteName & Space(lBUFFER_SIZE)

' Return the UNC path (eg.\\Server\Share).
lStatus = WNetGetConnection32( _
sDriveLetter, _
lpszRemoteName, _
cbRemoteName)

'// Has WNetGetConnection() succeeded.
'// WNetGetConnection()returns 0 (NO_ERROR)
'// if it succesfully retrieves the UNC path.
If lStatus = NO_ERROR Then
' Display the UNC path.
UNCPath = lpszRemoteName
Else
' Unable to obtain the UNC path.
UNCPath = "NO UNC path"
End If

End Function

Sub GetUNCPath()
Dim sDriveLetter As String
Dim cbRemoteName As Long
Dim lStatus As Long

Again:
'// Prompt the user to type the mapped drive letter.
sDriveLetter = UCase(InputBox( _
"Enter Drive Letter of Your Network" & _
"Connection." & Chr(10) & "eg. Y (NO colon)"))
If sDriveLetter = "" Then End
If Len(sDriveLetter) > 1 Then GoTo Again

'// Add a colon to the drive letter entered.
sDriveLetter = sDriveLetter & ":"

'// Specifies the size in charaters of the buffer.
cbRemoteName = lBUFFER_SIZE

' Prepare a string variable by padding spaces.
lpszRemoteName = lpszRemoteName & Space(lBUFFER_SIZE)

' Return the UNC path (eg.\\Server\Share).
lStatus& = WNetGetConnection32(sDriveLetter, _
lpszRemoteName, _
cbRemoteName)

'// Has WNetGetConnection() succeeded.
'// WNetGetConnection()returns 0 (NO_ERROR)
'// if it succesfully retrieves the UNC path.
If lStatus& = NO_ERROR Then
'// Display the UNC path.
MsgBox lpszRemoteName, vbInformation
Else
'// Unable to obtain the UNC path.
MsgBox "Unable to obtain the UNC path for " & _
sDriveLetter, vbInformation
End If

End Sub