Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function DavGetUNCFromHTTPPath Lib "Netapi32.dll" (ByVal Url As LongPtr, ByVal UncPath As LongPtr, lpSize As Long) As Long
#Else
Private Declare Function DavGetUNCFromHTTPPath Lib "Netapi32.dll" (ByVal Url As Long, ByVal UncPath As Long, lpSize As Long) As Long
#End If
'-----------------------------------------------------------------------------------------
' Convertit un chemin SharePoint de type (http...) en chemin UNC (\\...)
' Le chemin retourné a un séparateur final si le chemin initial en avait un
'-----------------------------------------------------------------------------------------
Public Function getUNCPath(pPath As String) As String
Dim lPath As String
Dim lUncPath As String
Dim lSize As Long
lSize = 260 ' MAX_PATH
lPath = pPath & vbNullChar ' Chemin + caractère null de fin
lUncPath = Space(lSize) ' Buffer de réception
If DavGetUNCFromHTTPPath(StrPtr(lPath), StrPtr(lUncPath), lSize) = 0 Then
' 0 = pas d'erreur
' on reçoit dans lSize la taille du chemin UNC (séparateur de fin inclus)
getUNCPath = Left(lUncPath, lSize - 1)
' Si le chemin initial avait un séparateur final, on en ajoute un
If Right(pPath, 1) = "/" Or Right(pPath, 1) = "\" Then
getUNCPath = getUNCPath & "\"
End If
Else
getUNCPath = pPath
End If
End Function