Set objDict = CreateObject("Scripting.Dictionary")
Dim RegEx As New Regex("[^a-z]")
Dim myStr As String = "a very very long string"
For Each strWord In Split(myStr," ")
strWord = RegEx.Replace(strWord,"")
If Not objDict.Exists(strWord) then
objDict.Add(strWord, 1)
Else
objDict.Item(strWord) += 1
End If
Next
For Each strKey In objDict.Keys
Msgbox(strKey & " appears " & objDict.Item(strKey) & " times")
Next
You can try using the Scripting.dictionary object to keep track of words:
And even use RegExp to get rid of punctuation marks and stuff...
Open in new window