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?
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
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
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 Microsoft MVP: 2011 - 2015 IMP Links : Acceptable Use Policy, FAQ MyGear:
ACER R7 (Win 8.1+Office 2013+VS2013) || Sony VPCCB-45FN with a Win10+Office 2010. || Mac Book Pro (10.6.8) with Office 2011
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 Microsoft MVP: 2011 - 2015 IMP Links : Acceptable Use Policy, FAQ MyGear:
ACER R7 (Win 8.1+Office 2013+VS2013) || Sony VPCCB-45FN with a Win10+Office 2010. || Mac Book Pro (10.6.8) with Office 2011
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 !
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 08: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
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
→ The Comprehensive Guide to Cloud Computing
A complete overview of Cloud Computing focused on what you need to know, from selecting a platform to choosing a cloud vendor.