Reputation: 2576
I'm using Application.FileDialog to let the user select a folder, as in:
Dim F As FileDialog
Set F = Application.FileDialog(msoFileDialogFolderPicker)
In this case the default folder contains no subfolders, so what the user sees is an empty box. Ideally, the dialog would not just list folders, but would list files disabled/grayed out so that the user would be able to see the contents of the folder he is picking.
Is there a way to do this on the cheap with a FileDialog or do I have to create my own form (ugh) ?
Upvotes: 4
Views: 9895
Reputation: 149287
Here is something from my database. I have been using this for quite sometime now for VBA. This code is not mine and I found it long time ago on the web.
Sub Sample()
ret = BrowseForFolder("C:\")
End Sub
Function BrowseForFolder(Optional OpenAt As Variant) As Variant
Dim ShellApp As Object
Set ShellApp = CreateObject("Shell.Application"). _
BrowseForFolder(0, "Please choose a folder", 0, OpenAt)
On Error Resume Next
BrowseForFolder = ShellApp.self.Path
On Error GoTo 0
Set ShellApp = Nothing
Select Case Mid(BrowseForFolder, 2, 1)
Case Is = ":"
If Left(BrowseForFolder, 1) = ":" Then GoTo Invalid
Case Is = "\"
If Not Left(BrowseForFolder, 1) = "\" Then GoTo Invalid
Case Else
GoTo Invalid
End Select
Exit Function
Invalid:
BrowseForFolder = False
End Function
Upvotes: 2