Hello yinkajewole,
This macro will return True if all of the search words are found in the text file. Case is ignored. You can interrupt the macro at anytime using the keys Ctrl+Break.
Function AreWordsInFile(ByVal File As String, ByVal SearchWords As String) As Boolean
Dim Data() As Byte
Dim i As Long
Dim n As Long
Dim Success As Boolean
Dim Text As String
Dim Word As String
SearchWords = SearchWords & " "
Open File For Binary Access Read As #1
ReDim Data(LOF(1))
Get #1, , Data
Close #1
Text = StrConv(Data, vbUnicode)
If Text = "" Then
MsgBox "The file is empty.": Exit Function
End If
i = 1
Success = True
Do
DoEvents
n = InStr(i, SearchWords, " ")
If n > 0 Then
Word = Mid(SearchWords, i, n - i)
i = n + 1
If InStr(1, Text, Word, vbTextCompare) = 0 Then
Success = False: Exit Do
End If
End If
If Word = "" Or i >= Len(SearchWords) Then Exit Do
Loop
AreWordsInFile = Success
End Function
Bookmarks