vbanewbie68
Board Regular
- Joined
- Oct 16, 2021
- Messages
- 171
- Office Version
- 365
- Platform
- Windows
- MacOS
Hello
This macro is unable to find a specific path folder to allow me to select which files I can choose. It works fine when open but I have to manually to find D: Drive and then to look for the folder and then select which files I can choose.
Could the path drive be too long?
Can you point me where it goes wrong please?
Thank you
Regards
V
This macro is unable to find a specific path folder to allow me to select which files I can choose. It works fine when open but I have to manually to find D: Drive and then to look for the folder and then select which files I can choose.
Could the path drive be too long?
Can you point me where it goes wrong please?
Thank you
Regards
V
VBA Code:
Sub FindFile()
Dim fso As Object 'FileSystemObject
Dim fld As Object 'Folder
Dim fl As Object 'File
Dim Mask As String
Set fso = CreateObject("scripting.FileSystemObject") ' late binding
Set fldStart = fso.GetFolder("D:\WS\WSD_st\OPS_\Data_Processing\imports\MyThankYou") ' <-- use your FileDialog code here
For Each fld In fldStart.Files
If InStr(1, fld.Name, "supporters-file*") > 0 Then ' to select which files
Set fl = fld
Exit For
End If
Next
If fld Is Nothing Then
With Application.FileDialog(msoFileDialogFilePicker)
'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