Function ExtractWords(WordsToFind() As String, FindInText() As String, Optional Keep As Boolean = True) As String()
Dim tmpArray() As String
Dim i As Long, intT1 As Long, intT2 As Long, j As Long, k As Long
'// check for empty variables//
If UBound(WordsToFind) = -1 Or UBound(FindInText) = -1 Then
Exit Function
End If
'// check if we have multiple words //
intT1 = UBound(WordsToFind)
intT2 = UBound(FindInText)
k = -1
For i = 0 To intT2 - 1
For j = 0 To intT1
If Keep = True Then
If InStr(1, FindInText(i), WordsToFind(j), vbTextCompare) > 0 Then
k = k + 1
ReDim Preserve tmpArray(k)
If Not inArray(FindInText(i), tmpArray()) Then
tmpArray(k) = Trim$(FindInText(i))
End If
End If
Else
If InStr(1, FindInText(i), WordsToFind(j), vbTextCompare) < 1 Then
k = k + 1
ReDim Preserve tmpArray(k)
If Not inArray(FindInText(i), tmpArray()) Then
tmpArray(k) = Trim$(FindInText(i))
End If
End If
End If
Next
Next
ExtractWords = tmpArray
End Function
Function inArray(SearchText As String, StringArray() As String) As Boolean
Dim tmpStrings() As String, tmpString As String
tmpString = Join(StringArray, " ")
tmpStrings() = Split(tmpString, SearchText)
If UBound(tmpStrings()) > 0 Then
inArray = True
Else
inArray = False
End If
End Function