Results 1 to 12 of 12

Thread: Question re FileDialog(msoFileDialogFolderPicker)

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,462

    Question re FileDialog(msoFileDialogFolderPicker)

    Using the following code, the selected Folder name does not show in the
    'Folder name:' comboBox one prior to 'OK'. Nothing appears except a choice from the dropdown list. Tried in Excel 2003 and 2007.

    The function returns the right foldername though.

    This is the same on 2 computers but a third (so I'm told) does show the name.

    Code:
    Function BrowseFolder()
     'Open the file dialog
    Dim RetVal As String
    Set BrowseFolder = Application.FileDialog(msoFileDialogFolderPicker)
    With BrowseFolder
        .Show
        If BrowseFolder.SelectedItems.Count > 0 Then
            RetVal = .SelectedItems(1)
        End If
    End With
    BrowseFolder = RetVal
    End Function
    What should it do and can I make it show the foldername anyhow?

    Thanks, ABB

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Question re FileDialog(msoFileDialogFolderPicker)

    ‘ Declare a variable as a FileDialog Object

    Dim fd As FileDialog

    ‘ Declare a variable to capture the selected item

    Dim varSI as Variant



    ‘ Create a FileDialog object as a Folder Picker dialog box

    Set fd = Application.FileDialog(msoFileDialogFolderPicker)



    With fd

    .Title = “Select folder…” ‘What ever text you want

    .AllowMultiSelect = False ‘Does not make much sense to set to true on FolderPicker

    .ButtonName = “Select” ‘What ever makes sense. Default is OK

    .IntialFileName = “G:\mydir” ‘To guide your user part of the way to where you need them to be

    ‘ Show the dialog and jump out if user presses cancel

    If .Show <> -1 Then GoTo EndDialog

    varSI = .SelectedItems(1) ‘use first entry because there will be only one

    End With
    from http://www.instantpages.ltd.uk/Office_FileDialog.htm
    filedialog is not available in xl2000, so can not test

    many dialogs can retain previous values if used in the same session, this maybe why it can work on 1 machine
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,462

    Re: Question re FileDialog(msoFileDialogFolderPicker)

    That's giving me the same result, westconn. As you click on a Folder
    the name is not displayed in the combo box to the left of the Select button.

    This gives the impression nothing is selected.

    Is this how it's meant to be ?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Question re FileDialog(msoFileDialogFolderPicker)

    well it is a file picker, not a folder browser

    search on shbrowseforfolder
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,462

    Re: Question re FileDialog(msoFileDialogFolderPicker)

    Quote Originally Posted by westconn1 View Post
    well it is a file picker, not a folder browser
    Regardless, should the selected Folder name show in the combo box, or not?
    The Details icon seems permenantly grayed out, too.

    search on shbrowseforfolder
    Thanks for the tip, but looks like not for VBA ??

    Regards, ABB

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,462

    Re: Question re FileDialog(msoFileDialogFolderPicker)

    Quote Originally Posted by AlexanderBB View Post
    Thanks for the tip, but looks like not for VBA ??
    Oops, sorry ignore that. Got sidetracked... I'm aready using shbrowseforfolder
    and wanted to use the FileDialogFolderPicker instead.

    It works fine for someone with Vista and Excel 2007 but not XP and 2007.
    Has anyone else had success with it?

    Thanks, ABB

  7. #7
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Question re FileDialog(msoFileDialogFolderPicker)

    Show me the workbook that you are using it in?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,462

    Re: Question re FileDialog(msoFileDialogFolderPicker)

    Hi Koolsid,

    If you just run up a new Excel and paste in the code in Msg 1 in this thread - what do you get ?

    I'll attach an image of results here. You can see the Selected Folder but no name in the combo box. Do you see a name there on your system ?
    Attached Images Attached Images  

  9. #9
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Question re FileDialog(msoFileDialogFolderPicker)

    Ok, I get it..

    In that case, why don't you use this instead...

    Code:
    Sub Sample()
        FolderBrowser "C:"
    End Sub
    
    Function FolderBrowser(Optional DefaultLocation As Variant) As Variant
        Dim ShApp As Object
         
        Set ShApp = CreateObject("Shell.Application"). _
        BrowseForFolder(0, "Please choose a folder", 0, DefaultLocation)
         
        On Error Resume Next
        FolderBrowser = ShApp.self.Path
        On Error GoTo 0
         
        Set ShApp = Nothing
         
        Select Case Mid(FolderBrowser, 2, 1)
        Case Is = ":"
            If Left(FolderBrowser, 1) = ":" Then GoTo SubExit
        Case Is = "\"
            If Not Left(FolderBrowser, 1) = "\" Then GoTo SubExit
        Case Else
            GoTo SubExit
        End Select
         
        Exit Function
         
    SubExit:
        FolderBrowser = False
    End Function
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,462

    Re: Question re FileDialog(msoFileDialogFolderPicker)

    Thanks Koolsid. That was worth a go, but doesn't let you go back a level if you re-use the last Path.
    shbrowseforfolder can't remember last path and always starts at the root.
    msoFileDialogFolderPicker is OK in Win7 but fails as described in XP.

    If no more suggestions I'll detect the OS and use FilePicker or shbrowseforfolder.
    Malcolm Fraser was right - life wasn't meant to be easy !

    Regards, ABB

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Question re FileDialog(msoFileDialogFolderPicker)

    in kools example
    if you pass a value for defaultlocation the browse dialog should start at that level, you can store this from the last call

    this is just using a shell object for the same as shbrowseforfolder
    Last edited by westconn1; Dec 7th, 2010 at 09:23 PM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,462

    Re: Question re FileDialog(msoFileDialogFolderPicker)

    Yes, I understand... but the reason for looking at alternatives to shBrowseFolder was to store and return to the last path used.... avoiding having to navigate all the way back through the same folders again. But you need to be able to go both ways from there. A default location is not really the solution as it would have to be C:\ which takes us back where we were.

    Just a pity FolderPicker works in Windows 7 and not XP, but finding why is far beyond me !

    Thank you both for the help and suggestions, though.
    Regards, ABB

Posting Permissions

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



Click Here to Expand Forum to Full Width