This is the code for the BrowseFolder function
Private Declare Function SHBrowseForFolder Lib "SHELL32.DLL" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long 'ITEMIDLIST
Private Declare Function SHGetPathFromIDList Lib "SHELL32.DLL" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
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
Public Function BrowseFolder(hWnd As Long, szDialogTitle As String) As String
On Local Error Resume Next
Dim X As Long, BI As BROWSEINFO, dwList As Long, szPath As String, wPos As Integer
BI.hOwner = hWnd
BI.lpszTitle = szDialogTitle
BI.ulFlags = BIF_RETURNONLYFSDIRS
dwlList = SHBrowseForFolder(BI)
szPath = Space$(512)
X = SHGetPathFromIDList(ByVal dwlList, ByVal szPath)
If X Then
wPos = InStr(szPath, Chr(0))
BrowseFolder = Trim(Left$(szPath, wPos - 1))
Else
BrowseFolder = vbNullString
End If
End Function
But when compile, the error variable not defined on BIF_RETURNONLYFSDIRS
How can I solve it ?
Private Declare Function SHBrowseForFolder Lib "SHELL32.DLL" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long 'ITEMIDLIST
Private Declare Function SHGetPathFromIDList Lib "SHELL32.DLL" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
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
Public Function BrowseFolder(hWnd As Long, szDialogTitle As String) As String
On Local Error Resume Next
Dim X As Long, BI As BROWSEINFO, dwList As Long, szPath As String, wPos As Integer
BI.hOwner = hWnd
BI.lpszTitle = szDialogTitle
BI.ulFlags = BIF_RETURNONLYFSDIRS
dwlList = SHBrowseForFolder(BI)
szPath = Space$(512)
X = SHGetPathFromIDList(ByVal dwlList, ByVal szPath)
If X Then
wPos = InStr(szPath, Chr(0))
BrowseFolder = Trim(Left$(szPath, wPos - 1))
Else
BrowseFolder = vbNullString
End If
End Function
But when compile, the error variable not defined on BIF_RETURNONLYFSDIRS
How can I solve it ?