ShellApp.BrowseForFolder to give Default Folder and allow browse for any Folder
Hi
_1) So in short: I want a code using the ShellApp.BrowseForFolder to give me a Dialogue box which allows
Both
me to browse and select a Folder ( from anywhere on my computer )
and
as well it having initially a default Initial Folder.
I have been struggling to get that and have only been able to get one or the other.
_....
_2) In more detail to help explain exactly what I want:
_ So I use often a code of this form ( Simplified to demo ) to select a Folder, whilst giving also a default suggestion.
_It uses the VBA .FileDialog(msoFileDialogFolderPicker). Nice simple code works well
(_... the only weird things I note is that on my default suggestionPlease Login or Register to view this content.
_a) the syntax is
.InitialFileName =
Which is a bit weird , I would have expected something like
.InitialFolderName =
Or better still
.InitialFolderPath =
_b) i have to add a “\" on the end of my “Initial File name, although that appears on none of my returned Strings..... _...but never mind those, unless out of interest you know why that is?...)
_..............
Now I am happy with that code above. But I would like an alternative, and have seen the ShellApp.BrowseForFolder often given.
Generally I can get the ShellApp.BrowseForFolder version to work , but with a couple of problems .
_ a) I cannot seem to get a form of the dialogue box to come up with
both
a default suggestion
and
the ability to browse for a Folder. I only seem to be able to get one of the other. Here then two examples,
The first, code2a, gives you a default suggestion, but the ability to browse is lost. That makes of course this first code useless – you might as well hard copy the Folder name and be done!!!
_.......Please Login or Register to view this content.
_b) Code2b allows you to browse, but I have no default suggestion.
In addition, the Folder path returned , comes up sometimes in a peculiar form. For example if I select “Computer” as my Folder, then the correct Folder name is returned as
“Computer”
However the path returned comes out as
"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
_.....Please Login or Register to view this content.
So can anyone clear up this weirdaty, and give me a code which uses ShellApp.BrowseForFolder and gives me a dialogue box with a default Folder and the ability to browse. ( and returns maybe always the “normal” looking path )
Thanks
Alan
_......
_....
P.s. The documentation is bad, or so my many hours of googling suggests.
I did find some info here:
http://wsh2.uw.hu/ch12f.html
Summarised here are the options. But despite many hours of experimenting I could find no combination the gave my desired dialogue box...
' objDlg.BrowseForFolder(hWnd, Title, Options[, Root])
'
'The first parameter submits a window handle to the dialog box. You should always use the value 0 for this parameter because the script has no handle.
'
'The second parameter specifies the string shown in the dialog box below the title bar
'
'The third parameter is a 32-bit flag that specifies internal features of the dialog box.....
'.... &H0001=1 Only file system folders can be selected. If this bit is set, the OK button is disabled if the user selects a folder that doesn't belong to the file system (such as the Control Panel folder).
'.... &H0002=2 The user is prohibited from browsing below the domain within a network (during a computer search).
'.... &H0004=4 Room for status text is provided under the text box. (I haven't found a way to show the status, however.)
'.... &H0008= etc. Returns file system ancestors only.
'.... &H0010 Shows an edit box in the dialog box for the user to type the name of an item.
'.... &H0020 Validate the name typed in the edit box.
'.... &H1000 Enables the user to browse the network branch of the shell's namespace for computer names.
'.... &H2000 Enables the user to browse the network branch of the shell's namespace for printer names.
'.... &H4000 Allows browsing for everything.
'
'The fourth parameter is optional and can be used to preselect a folder in the dialog box.
' You can submit a string with the folder's path (such as C:\Born) or you can use one of the values below to select a special folder object in the shell's namespace.
' .. 0 The Desktop (virtual) folder is the root directory. Using this constant along with &H0001 for the third parameter circumvents problems with the OK button.
' ..1 Internet Explorer is the root.
' ..2 The Programs folder of the Start menu is the root.
' ..3 The Control Panel folder is the root. The third parameter must be set to &H4000 (browse for everything).
' ..4 The Printers folder is the root. The third parameter must be set to &H4000 (browse for everything).
' ..5 The Documents folder of the Start menu is the root.
' ..6 The Favorites folder of the Start menu is the root.
' ..7 The Startup folder of the Start menu is the root. The third parameter must be set to &H4000 (browse for everything).
' ..8 The Recent folder is the root. The third parameter must be set to &H4000 (browse for everything).
' ..9 The SendTo folder is the root. The third parameter must be set to &H4000 (browse for everything).
' ..10 The Recycle Bin folder is the root. The third parameter must be set to &H4000 (browse for everything).
' ..11 The Start menu folder is the root.
' ..16 The Desktop (physical) folder is the root.
' ..17 My Computer is the root.
' ..18 Network Neighborhood is the root.
' ..19 The Nethood folder is the root.
' ..20 The Fonts folder is the root.
' ..21 The Templates folder is the root.
Rem Ref
' http://www.excelforum.com/excel-prog...ny-folder.html
' http://www.mrexcel.com/forum/excel-q...orkbook-2.html
' http://www.mrexcel.com/forum/excel-q...xcel-file.html
Bookmarks