I'm currently trying to work through a solution that will allow the user to determine a folder on their computer where certain files are stored (using folder picker tool).
Once that folder is set, I want to look there for a file that has a name like "File 1". Please note, I don't have the full file name, it will change rom person to person. For example the full name may be "123456 File1 abcde.xlsx"
Current attempt is as follows (this produced an error)
Sub SelectFolder()
Dim wb As Workbook
Dim sFolder As String
' Open the select folder prompt
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = -1 Then ' if OK is pressed
End If
End With
If sFolder <> "" Then ' if a file was chosen
For Each wb In sFolder
If wb.Name Like ("Extract 1 Dividends") Then
wb.Open
End If
Next wb
End Sub
This is producing an error as once the user selects and set sFolder string, I cant seem to look in that string for the file I wan't. I get the following error
For each may only iterate over a collection object or an array
Is there an alternative strategy I can try?