View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
MD MD is offline
external usenet poster
 
Posts: 26
Default Browse for folder

Well done Jim. Thank you for your tip

Regards,

Michel


"Jim Rech" a écrit dans le message de
...

it does not seem to work in the old SHELL32.dll format.


I'll take your word for it that old Shell functions do not support UNC
paths.

This means that ALL the computers in our office need to be maped!!!


Not necessarily. Have you considered a temporary mapping? See Sub Demo
below.


Declare Function WNetAddConnection Lib "mpr.dll" Alias

"WNetAddConnectionA"
_
(ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal
lpszLocalName As String) As Long

Declare Function WNetCancelConnection Lib "mpr.dll" Alias
"WNetCancelConnectionA" _
(ByVal lpszName As String, ByVal bForce As Long) As Long

Declare Function WNetGetConnection Lib "mpr.dll" _
Alias "WNetGetConnectionA" (ByVal lpszLocalName As String, _
ByVal lpszRemoteName As String, cbRemoteName As Long) As Long

Declare Function GetDriveTypeA Lib "KERNEL32" _
(ByVal DriveNumber As String) As Integer

Sub Demo()
Dim TempMap As String
TempMap = GetAvailDriveLtr
If TempMap < "" Then
Connect TempMap & ":", "\\PMA0010F09\SYS1"
MsgBox TempMap & " is available"
''Do Browse using TempMap
DisConnect TempMap & ":"
End If
End Sub

Function GetAvailDriveLtr() As String
Dim DrvCtr As Integer, DrvType As Integer
For DrvCtr = Asc("C") To Asc("Z")
DrvType = GetDriveTypeA(Chr(DrvCtr) & ":\")
If DrvType < 0 And DrvType < 2 Then
GetAvailDriveLtr = Chr(DrvCtr)
Exit Function
End If
Next
End Function

Sub Connect(sDrive, sService As String)
On Error GoTo Err_Connect
WNetAddConnection sService & Chr(0), "" & Chr(0), sDrive & Chr(0)
Err_Connect:
End Sub

Sub DisConnect(sDrive As String)
On Error GoTo Err_DisConnect
WNetCancelConnection sDrive + Chr(0), 0
Err_DisConnect:
End Sub


--
Jim Rech
Excel MVP