I have the below code which returns all file names of .txt files in a folder directory. I would like to add to this code to open the txt file and search for a user provided string and return true or false if the string is found in the file.
Any help would be much appreciated.
Sub VBAF1_List_All_TXT_Files_Using_Dir()
'Variable Declaration
Dim sFilePath As String
Dim sFileName As String
Dim sUserString As String
'Specify File Path
sFilePath = "C:\Users\d85307\Documents\Automation Anywhere Files\Automation Anywhere\My Docs\UK\Vehicle Delivery\ATDC\Log"
' sUserString =
'Check for back slash
If Right(sFilePath, 1) <> "\" Then
sFilePath = sFilePath & "\"
End If
sFileName = Dir(sFilePath & "*.txt")
Do While Len(sFileName) > 0
If Right(sFileName, 3) = "txt" Then
'Display file name in immediate window
Debug.Print sFileName
End If
'Set the fileName to the next available file
sFileName = Dir
Loop
End Sub