Browse for Folder and get the Folder Location
Requirements:
CommandButton -- Name: cmdBrowse
TextBox -- Name: txtRemotePath
Private Declare Function SHBrowseForFolder Lib "shell32.dll" (ByRef lpbi As Browseinfo) As Long
Private Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath As String) As Long
Private Type Browseinfo
hwnd As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Integer
End Type
Private Sub cmdBrowse_Click()
Dim fret As Long
Dim buffer As String, folder As String
Dim bInfo As Browseinfo
'---------------------
bInfo.hwnd = Me.hwnd
bInfo.pszDisplayName = Space(255)
bInfo.ulFlags = &O1
bInfo.iImage = 0
bInfo.lParam = 0
bInfo.lpfn = 0
bInfo.pidlRoot = 0
bInfo.lpszTitle = "Select the folder of your choice."
buffer = Space(255)
fret = SHGetPathFromIDList(SHBrowseForFolder(bInfo), buffer)
buffer = RTrim(buffer)
folder = Left(buffer, Len(buffer) - 1)
If folder <> vbNullString Then 'user selected OK
If Right(folder, 1) <> "\" Then folder = folder + "\"
txtRemotePath.Text = folder
End If
End Sub
Enjoy!