Declare PtrSafe Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As LongPtr
Declare PtrSafe Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As LongPtr, ByVal pszPath As String) As Boolean
Public Type BROWSEINFO
hOwner As LongPtr
pidlRoot As LongPtr
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As LongPtr
lParam As LongPtr
iImage As Long
End Type
Function saGetFolder(Title, Optional NewBTN) As String
Dim bInfo As BROWSEINFO, pPath As String
Dim r As Boolean, POS As Integer
Dim pidl
If IsMissing(NewBTN) Then NewBTN = True
bInfo.pidlRoot = 0&
bInfo.lpszTitle = Title
If NewBTN = True Then
bInfo.ulFlags = &H41
Else
bInfo.ulFlags = &H241
End If
pidl = SHBrowseForFolder(bInfo)
pPath = Space$(512)
r = SHGetPathFromIDList(ByVal pidl, ByVal pPath)
If r Then
POS = InStr(pPath, Chr$(0))
saGetFolder = Left(pPath, POS - 1)
Else
saGetFolder = ""
End If
End Function