vbanewbie68
Board Regular
- Joined
- Oct 16, 2021
- Messages
- 171
- Office Version
- 365
- Platform
- Windows
- 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
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