PDA

View Full Version : VBA to Return the UNC(Universal Naming Convention) Path of a Mapped Network Drive



Admin
09-06-2011, 01:31 AM
Hi All,

Here is a VBA method to get the UNC path of a mapped drive.


Option Explicit

Function GETNETWORKPATH(ByVal DriveName As String) As String

Dim objNtWork As Object
Dim objDrives As Object
Dim lngLoop As Long


Set objNtWork = CreateObject("WScript.Network")
Set objDrives = objNtWork.enumnetworkdrives

For lngLoop = 0 To objDrives.Count - 1 Step 2
If UCase(objDrives.Item(lngLoop)) = UCase(DriveName) Then
GETNETWORKPATH = objDrives.Item(lngLoop + 1)
Exit For
End If
Next

End Function

Sub kTest()

MsgBox GETNETWORKPATH("K:")

End Sub