VBA How to change from Filepicker to Folderpicker using FSO

vbanewbie68

Board Regular
Joined
Oct 16, 2021
Messages
171
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello

One of the procedures has a Filepicker code to select a specific file. I would like to change it to Folderpicker instead so I have options to choose any files I can select.

With your help on this is much appreciated.

Thank you

Sub FindFile()

Dim fso As Object 'FileSystemObject
Dim fld As Object 'Folder
Dim fl As Object 'File
Dim Mask As String




Set fldStart = fso.GetFolder("J:imports\ThankYou\") ' <-- use your FileDialog code here
Debug.Print fldStart



For Each fld In fldStart.Files
If InStr(1, fld.Name, "supporters-file,*csv", vbTextCompare) > 1 Then
Set fl = fld
Exit For
End If
Next

If fld Is Nothing Then


With Application.FileDialog(msoFileDialogFilePicker)

.Title = "Select a Folder"
'Makes sure the user can select only one file
.AllowMultiSelect = False
'Show the dialog box
.Show


'Store in fullpath variable
Set fl = fso.GetFile(.SelectedItems.Item(1))
End With
End If

Set tempbook = Workbooks.Open(fl.Path, Local:=True)


End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
AFAIK:
- fso doesn't provide a dialog but if it does, would like to learn of it from others
- Application.GetOpenFileName will show files but not allow you to just pick the folder
- msoFileDialogFolderPicker will not show files in the folder
- msoFileDialogFilePicker will show files but not allow you to just pick the folder

so this
change it to Folderpicker instead so I have options to choose any files
doesn't seem doable. I guess it depends on how one interprets that. You can multi select files if that helps. You can also strip out the file name or path to the file.
 
Upvote 0
AFAIK:
- fso doesn't provide a dialog but if it does, would like to learn of it from others
- Application.GetOpenFileName will show files but not allow you to just pick the folder
- msoFileDialogFolderPicker will not show files in the folder
- msoFileDialogFilePicker will show files but not allow you to just pick the folder

so this

doesn't seem doable. I guess it depends on how one interprets that. You can multi select files if that helps. You can also strip out the file name or path to the file.

Thank you for this. I have managed to fix the issue by adding ChDrive and ChDir to join this procedure to GetFile. It works.

Regards

V
 
Upvote 0
It would be useful to others if you mark this as solved then.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,591
Messages
6,120,424
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top