트릭은 단어 사전을 분할하고 분할 된 항목을 하나씩 검색하는 것입니다. 하나라도 발견되면 부울 hasWord
은 True
으로 변경됩니다. 그런 다음이 부울 값을 기준으로 올바른 MsgBox
텍스트가 주어집니다 :
Sub TestMe()
Dim sentence As String
Dim wordDictonary As String
Dim myArray As Variant
Dim cnt As Long
Dim hasWord As Boolean
sentence = "may have linked documents from another"
wordDictonary = "linkeD, mAy, From "
sentence = LCase(sentence)
wordDictonary = LCase(wordDictonary)
myArray = Split(wordDictonary, ",")
For cnt = LBound(myArray) To UBound(myArray)
If InStr(1, sentence, Trim(myArray(cnt))) Then hasWord = True : Exit For
Next cnt
MsgBox (IIf(hasWord, "Contains a word", "Does not contain a word!"))
End Sub
는 크고 작은 문자를 무시하려면 sentence
과 wordDictionary
변수는 LCase
와 소문자된다.
: 어떻게 당신이 당신의 배열을 생성하는 것은 당신에게 달려 있지만, 여기에 예입니다 |에서) \ b 참조 : https://stackoverflow.com/questions/22542834/how-to-use-regular-expressions-regex-in-microsoft-excel-both-in-cell-and-loops –