Get a folder
This function will open a dialog that will display the folders on your computer which you can then choose one from. The second form only opens at the working directory level.
Function getFolder()
Dim BrowseFolder As String
Dim oFolder, oFolderItem
Dim oPath, oShell, strPath
Set oShell = CreateObject( "Shell.Application" )
Set oFolder = oShell.Namespace(17) 'the 17 indicates that we are looking at the virtual folder that contains everything on the local computer
Set oFolderItem = oFolder.Self
Set strPath = oFolderItem.Path
Set oFolder = oShell.BrowseForFolder(0, "Please select the folder where the files are located:", 1, strPath)
If (Not oFolder is Nothing) Then
Set oFolderItem = oFolder.Self
oPath = oFolderItem.Path
If Right(oPath, 1) <> "\" Then
oPath = oPath & "\"
End If
End If
getFolder = oPath
End Function
Function getFolder() 'this one uses the working directory as the highest level directory
Dim BrowseFolder As String
Dim oFolder, oFolderItem
Dim oPath, oShell, strPath
Dim Current As Variant 'per Windows documentation this is defined as a variant and not a string
Set oShell = CreateObject( "Shell.Application" )
Set oFolder = oShell.Namespace(17) 'the 17 indicates that we are looking at the virtual folder that contains everything on the local computer
Current = Client.WorkingDirectory()
Set oFolder = oShell.BrowseForFolder(0, "Please select the folder where the files are located:", 1, Current)
If (Not oFolder is Nothing) Then
Set oFolderItem = oFolder.Self
oPath = oFolderItem.Path
If Right(oPath, 1) <> "\" Then
oPath = oPath & "\"
End If
End If
getFolder = oPath
End Function
The shell application is not
The shell application is not part of IDEA but part of the windows operating system. You can find more info on it here:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb774094(v=vs…
Hi Brian,
Hi Brian,
documentation has moved to the following links:
https://docs.microsoft.com/en-us/windows/win32/shell/shell-namespace
https://docs.microsoft.com/en-us/windows/win32/api/shldisp/ne-shldisp-s…
https://docs.microsoft.com/en-us/windows/win32/shell/shell-browseforfol…
Besides some further annotations to your code:
- String variable BrowseFolder is declared but not used ==> not necessary
- oPath suggests that the variable type is an Object but it is a String - so sPath maybe would be more clearly
More information on Shell
What exactly is the shell application and other uses can it have?
Is it documented anywhere in the language browser tool or how did you know about it, because I have been stressing on how to create such a dialog box.