Bonsoir Flac..
En haut d'un module de code standard, colle le code suivant:
'=========>>
Option Explicit
Declare Function WNetGetConnection32 _
Lib "mpr.dll" _
Alias "WNetGetConnectionA" ( _
ByVal lpszLocalName As String, _
ByVal lpszRemoteName As String, _
lSize As Long) _
As Long
Dim lpszRemoteName As String
Dim lSize As Long
Const NO_ERROR As Long = 0
Const lBUFFER_SIZE As Long = 1052
'--------->>
Public Function fnUNCPath(strDriveLetter As String) 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.
strDriveLetter = Left(strDriveLetter, 1) & ":"
'// 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( _
strDriveLetter, _
lpszRemoteName, _
cbRemoteName)
'// Has WNetGetConnection() succeeded.
'// WNetGetConnection()returns 0 (NO_ERROR)
'// if it succesfully retrieves the UNC path.
If lStatus = NO_ERROR Then
'// Get UNC path.
fnUNCPath = lpszRemoteName
Else
'// Unable to obtain the UNC path.
fnUNCPath = "NO UNC path"
End If
End Function
'<<=========
Postscriptum:
En passant, dans ton code, tu devrais remplacer
Sub mamacro()
On Error Resume Next
Application.ScreenUpdating = False
applicationenableevents = False
[...]
applicationenableevents = True
Application.ScreenUpdating = True
End sub
avec quelque chose comme:
'=========>>
Public Sub mamacro()
On Error GoTo ErrHandler
Application.ScreenUpdating = False
Application.EnableEvents = False
[...]
XIT:
Application.EnableEvents = True
Application.ScreenUpdating = True
On Error GoTo 0
Exit Sub
ErrHandler:
Call MsgBox( _
Prompt:="Erreur " & Err.Number _
& " (" & Err.Description & ") " _
& "dans la macro mamacro", _
Buttons:=vbCritical, _
Title:="ERREUR")
Resume XIT
End Sub
'<<=========
Il y a deux raisons à ma suggestion:
- l'instruction applicationenableevents manque d'un point entre
Application et EnableEvents
- En utilisant l'instruction
On Error Resume Next
toute erreur ultérieure sera simplement ignorée.
Cela peut parfois être souhaitable - mais pas ici - et, dans tous les cas,
il ne faut l'utiliser qu'avec précaution!
===
Regards,
Norman
