+ Reply to Thread
Results 1 to 9 of 9

ShellApp.BrowseForFolder to give Default Folder and allow browse for any Folder

  1. #1
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    ShellApp.BrowseForFolder to give Default Folder and allow browse for any Folder

    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
    Please Login or Register  to view this content.
    (_... the only weird things I note is that on my default suggestion
    _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
    Last edited by Doc.AElstein; 05-27-2016 at 05:47 AM.
    '_- Google first, like this _ site:ExcelForum.com Gamut
    Use Code Tags: Highlight code; click on the # icon above,
    Post screenshots COPYABLE to a Spredsheet; NOT IMAGES PLEASE
    http://www.excelforum.com/the-water-...ml#post4109080
    https://app.box.com/s/gjpa8mk8ko4vkwcke3ig2w8z2wkfvrtv
    http://excelmatters.com/excel-forums/ ( Scrolll down to bottom )

  2. #2
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: ShellApp.BrowseForFolder to give Default Folder and allow browse for any Folder

    Try this and modify to suit your saving needs:
    currently set to save MyFileName.xlsx to the selected folder


    Please Login or Register  to view this content.
    If a response has helped then please consider rating it by clicking on *Add Reputation below the post
    When your issue has been resolved don't forget to mark the thread SOLVED (click Thread Tools at top of thread)

  3. #3
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: ShellApp.BrowseForFolder to give Default Folder and allow browse for any Folder

    Hi Kevin
    Thanks for the reply. Your code is basically the one I gave at the start of the Thread which uses the VBA FileDialog(msoFileDialogFolderPicker). As I mentioned I have no problem with that.

    I am trying to do the same using the ShellApp.BrowseForFolder alternative, that is to say using ShellApp.BrowseForFolder to give a dialogue box with a Default Folder and allowing browsing for any Folder

    Thanks anyway for taking the time to reply.
    Alan
    Last edited by Doc.AElstein; 05-24-2016 at 04:54 AM.

  4. #4
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: ShellApp.BrowseForFolder to give Default Folder and allow browse for any Folder

    try this

    - answer is either 1 OR 2 OR type in full path when requested
    - you need to add error traps for bad input!

    Please Login or Register  to view this content.
    Last edited by Kevin#; 05-24-2016 at 05:38 AM.

  5. #5
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: ShellApp.BrowseForFolder to give Default Folder and allow browse for any Folder

    Thanks for coming back Kevin and thanks for the code.

    _1 ) your code errors at compile at this line
    Please Login or Register  to view this content.
    The error says that ws is not declared.

    _2 )
    If I understand correctly it is a workaround.

    In your basic code idea, If I choose my default path in the First input box, then I do not need to open the Dialogue box to select again that default path.

    So a slightly different version of your code would be

    Please Login or Register  to view this content.
    It is a nice workaround Thanks.

    But it basically avoids the issue of not being able to browse with a dialogue box which also initially highlights a default Folder using ShellApp.BrowseForFolder

    So I will leave the thread as unsolved as
    _1) I am puzzled that I cannot achieve the same result as with our simple FileDialog(msoFileDialogFolderPicker) using the ShellApp.BrowseForFolder.
    I am wondering if there is a bug, or it is just a case of getting the correct arguments...
    In my second code using the ShellApp.BrowseForFolder, for example , the dialogue box comes up thus:
    code2aShellAppDialogue.JPG

    As i have indicated there is an instruction
    “Klicken Sie auf das Symbol neben einem Ordner, um Unterordner anzuzeigen”
    Which roughly translate in English to
    “Click on the icon next to a folder to display a subfolder”
    Clicking anywhere to the left has no effect. If it did you could navigate to choose a different Folder.

    _2) The workaround code still gives me a strange output for some things , such as when I select “computer” – instead of it returning the string computer i get the strange
    "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
    Once again

    _....

    It is not a big issue.
    But maybe someone familiar with the ShellApp.BrowseForFolder can shed some light on where i am going wrong here. I assume it must or should be possible to use the ShellApp.BrowseForFolder to give a Default Folder and allow browse for any Folder in the same dialogue box as we have done with the FileDialog(msoFileDialogFolderPicker)

    Thanks again for your reply. Appreciate it
    Maybe someone else can enlighten us.

    Alan

  6. #6
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: ShellApp.BrowseForFolder to give Default Folder and allow browse for any Folder

    Try this then

    Please Login or Register  to view this content.
    "Computer" is the highest level folder on my computer. You will need to amend that

    Computer.jpg

  7. #7
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: ShellApp.BrowseForFolder to give Default Folder and allow browse for any Folder

    Sorry Kevin you have lost me. No offence, I am very grateful for your attempts to help. But I think you have missed the point. Apologies if I have not explained well enough.

    _.....This last code from you , ( corrected for "Computer" rather than Computer )
    Please Login or Register  to view this content.
    _..................Is equivalent to my original code, code2a, Post #1
    This gives me the ability to browse. But not a Default Path

    The issue remains trying to use the ShellApp.BrowseForFolder to give a Default Folder and allow browse for any Folder in the same dialogue box as we have done with the FileDialog(msoFileDialogFolderPicker)
    Last edited by Doc.AElstein; 05-24-2016 at 09:36 AM.

  8. #8
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: ShellApp.BrowseForFolder to give Default Folder and allow browse for any Folder

    Apologies for not being clearer. This is where my mind was heading!

    Please Login or Register  to view this content.

  9. #9
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: ShellApp.BrowseForFolder to give Default Folder and allow browse for any Folder

    Hi Kevin,
    I understand excactly what you are suggesting.

    You have given me in Post #8 the same answer as Post # 4

    My reply is the same. It is a nice workaround, thanks. ( But again no need to open the dialogue box if you choose the deafult. - No point in choosing it again! )
    '
    Please Login or Register  to view this content.
    _...
    Thanks once again for the Workaround.

    Alan

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA-Open At Specific Folder with BrowseForFolder
    By michaelisk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-08-2013, 05:51 PM
  2. [SOLVED] vb macro browse folder
    By ccs_1981 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-19-2012, 05:46 AM
  3. Changing Folder from the default folder
    By cg7131 in forum Excel Programming / VBA / Macros
    Replies: 30
    Last Post: 08-29-2011, 04:56 PM
  4. Different 'Browse for Folder' dialog?
    By Jon.R in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-14-2011, 02:30 PM
  5. Browse for folder error
    By abousetta in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-29-2010, 05:26 PM
  6. Copy Folder Using Browse
    By davehunter in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-23-2007, 12:41 PM
  7. [SOLVED] Full folder path from BrowseForFolder
    By Jon in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-02-2006, 06:15 PM
  8. Browse for folder
    By Steph in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-08-2005, 12:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1