Return *Full* Path Via A Pop Up

oliver_penney

Board Regular
Joined
Dec 18, 2002
Messages
182
hi all

i have some code to return a path by giving the user a pop up and a windows explorer type thing

only problem is it returns the mapped drive, not the server & path

e.g. "P:\my documents\" not "\\dldnc033pn2\_penneyol$\My Documents\"

anyone have any code to return the full path?

thanx

ol

btw, here's the code (not mine, found it)

Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _
"SHGetPathFromIDListA" (ByVal pidl As Long, _
ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
"SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
As Long

Private Const BIF_RETURNONLYFSDIRS = &H1


Public Function BrowseFolder(szDialogTitle As String) As String
Dim x As Long, bi As BROWSEINFO, dwIList As Long
Dim szPath As String, wPos As Integer

With bi
.hOwner = hWndAccessApp
.lpszTitle = szDialogTitle
.ulFlags = BIF_RETURNONLYFSDIRS
End With
dwIList = SHBrowseForFolder(bi)
szPath = Space$(512)
x = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)

If x Then
wPos = InStr(szPath, Chr(0))
BrowseFolder = Left$(szPath, wPos - 1)
Else
BrowseFolder = ""
End If

End Function
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi

The following code is something of a workaround, and there may be more direct ways to achieve what you want, but you can identify the Server name from the mapped drive letter using the following, and then rebuild your path using it:

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> NetworkMapDrive()

<SPAN style="color:#00007F">Set</SPAN> WshNetwork = CreateObject("WScript.Network")
<SPAN style="color:#00007F">Set</SPAN> oDrives = WshNetwork.EnumNetworkDrives
DrivesStr = "Network drive Mappings:" & Chr(13)

<SPAN style="color:#00007F">For</SPAN> i = 0 <SPAN style="color:#00007F">To</SPAN> oDrives.Count - 1 <SPAN style="color:#00007F">Step</SPAN> 2
DrivesStr = DrivesStr & "Drive " & oDrives.Item(i) & " = " & oDrives.Item(i + 1) & Chr(13)
<SPAN style="color:#00007F">Next</SPAN>
MsgBox DrivesStr
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
you will need to convert the Drive letter to it's UNC convention

try this...??

Code:
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 = 1052

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
 
Upvote 0

Forum statistics

Threads
1,216,126
Messages
6,129,007
Members
449,480
Latest member
yesitisasport

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top