Stuart McLachlan
stuart at lexacorp.com.pg
Wed Jul 6 08:02:41 CDT 2011
If you want to select a folder, you don't use OpenFilename(), you use ShBrowseForFolder() Private Declare Function SHBrowseForFolder Lib "SHELL32.DLL" _ Alias "SHBrowseForFolderA" (lpbi As BROWSEINFO) As Long Private Declare Function SHGetPathFromIDList _ Lib "shell32" Alias "SHGetPathFromIDListA" _ (ByVal Pidl As Long, ByVal pszPath As String) As Long Type BROWSEINFO hwndOwner As Long pIDLRoot As Long pszDisplayName As String * 256 lpszTitle As String * 256 ulFlags As Long lpfnCallback As Long lParam As Long iImage As Long End Type Const BIF_RETURNONLYFSDIRS = 1 Const BIF_DONTGOBELOWDOMAIN = 2 Const MAX_PATH = 260 Function BrowseForFolder(hwnd As Long, Title As String) As String Dim strPath As String strPath = Space$(MAX_PATH) Dim bi As BROWSEINFO Dim lpIDList As Long strPath = Space$(MAX_PATH) bi.hwndOwner = 0 bi.lpszTitle = Title bi.ulFlags = BIF_RETURNONLYFSDIRS Or BIF_DONTGOBELOWDOMAIN lpIDList = SHBrowseForFolder(bi) If lpIDList Then SHGetPathFromIDList lpIDList, strPath strPath = Left(strPath, InStr(1, strPath, vbNullChar) - 1) If Len(strPath) > 3 Then strPath = strPath & "\" BrowseForFolder = strPath End If End Function -- Stuart On 6 Jul 2011 at 8:39, Arthur Fuller wrote: > Thanks for this. It does appear to work nicely for selecting a file, > but I'm not sure how to modify it to return the selected directory > rather than a file in it. > > A. > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com >