If .InitialFileName
isn't set, the "Select Folder" dialog FileDialog(msoFileDialogFolderPicker)
uses the current directory of the application.
Is there any way to force the dialog to the "root" folder in Windows explorer ("This PC" in Windows 10, "My Computer" in earlier versions) ?
Public Function GetFolderName(InitPath As String) As String
With Application.FileDialog(msoFileDialogFolderPicker)
If InitPath <> "" Then
If Right$(InitPath, 1) <> "\" Then
InitPath = InitPath & "\"
End If
.InitialFileName = InitPath
Else
.InitialFileName = "" ' <-- What can I put here to start at "This PC" ?
End If
If .Show() = True Then
If .SelectedItems.Count > 0 Then
GetFolderName = .SelectedItems(1)
End If
End If
End With
End Function
Shell.Application.BrowseForFolder
uses the magic number 17 to specify this:
? CreateObject("Shell.Application").BrowseForFolder(0, "", &H11, 17).Self.Path
I don't like to use BrowseForFolder, because if an initial folder is specified, the user is limited to this folder and below.
.InitialFileName
string. How about a hybrid solution where you pick the dialog based on the supplied initial path? If empty, show one else the other. – ExaltationC:\
? – Autotomize