I'm trying to find a file in subfolder. Found this code, and with the full filename it works, but now I want to find the file with a partial I know. Something like this:
If myFile.Name = "*344148*" Then
But this is not working, below the complete code
Function Recurse(sPath As String) As String
Dim FSO As New FileSystemObject
Dim myFolder As Folder
Dim mySubFolder As Folder
Dim myFile As File
Set myFolder = FSO.GetFolder(sPath)
For Each mySubFolder In myFolder.SubFolders
For Each myFile In mySubFolder.Files
Debug.Print myFile.Name
Debug.Print myFile
' If myFile.Name = "*" & Range("B2").Value & "*" Then
' If myFile = "*" & Range("B2").Value & "*" Then
If myFile.Name = "*344148*" Then
Debug.Print myFile.Name & " in " & myFile.Path 'Or do whatever you want with the file
Workbooks.Open myFile.Path '& myFile.Name
Exit For
End If
Next
Recurse = Recurse(mySubFolder.Path)
Next
End Function
Sub TestR()
Call Recurse("P:\NetworkLocation\")
End Sub