1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
   | Private Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" _
 (ByVal lpszLocalName As String, ByVal lpszRemoteName As String, cbRemoteName As Long) As Long
 
Public Function fnctGetUNCPath(ByVal PathName As String) As String
 
'fonction donnée par GAYOT sur forum, discussion ouverte par MG
'http://www.developpez.net/forums/d1025923/logiciels/microsoft-office/excel/macros-vba-excel/recherche-repertoire-libelle-integral/
 
'comment récupérer le chemin intégral du fichier si connection lecteur réseau
'tuto :
'http://access.developpez.com/sources/?page=reseau#GetUNC
 
Const MAX_UNC_LENGTH  As Integer = 512
Dim strUNCPath As String
Dim strTempUNCName As String
Dim lngReturnErrorCode  As Long
 
  strTempUNCName = String(MAX_UNC_LENGTH, 0)
  lngReturnErrorCode = WNetGetConnection(Left(PathName, 2), strTempUNCName, _
    MAX_UNC_LENGTH)
 
  If lngReturnErrorCode = 0 Then
     strTempUNCName = Trim(Left(strTempUNCName, InStr(strTempUNCName, vbNullChar) - 1))
     strUNCPath = strTempUNCName & Mid(PathName, 3)
  End If
 
fnctGetUNCPath = strUNCPath
End Function | 
Partager