Skip to content

Instantly share code, notes, and snippets.

@kmondesir
Created September 7, 2019 12:04
Show Gist options
  • Save kmondesir/74e555cccda35706072a779a158fc59b to your computer and use it in GitHub Desktop.
Save kmondesir/74e555cccda35706072a779a158fc59b to your computer and use it in GitHub Desktop.
Counts groups of words and highlights them in a word document
Sub HitHighLighter3()
    'Modified to include a count of all words found in the document.
    'Modified 24 May 2014 by Kino Mondesir
    Dim words() As Array, list As String, wholeDocument As Range, list as Dictionary, report As String, _
source As String, destination As String
    words = Split(InputBox("Word HitHighLighter", "Please enter each word separated by a comma") , ",")
    list = New Dictionary
     source =  Environ("UserProfile")  & "\" & "Documents" & "\" & "Input"
     destination = Environ("UserProfile")  & "\" & "Documents" & "\" & "Output"
    For Each word in words
          With list
          .CompareMode = BinaryCompare
          .Add Key:=word, Item:=wordcounter(word)
          End With
    Next
    For Each word in words
        report = report & word & ":" & vbTab & list.item(word) & vbNewLine
        total = total + list.item(word)
    Next
    
    report = report & "total" & ":" & vbTab & total
    MsgBox report, vbOKOnly, "Count of Each Word in List"
    WriteToText destination, ActiveDocument.Name & ".txt", report
    
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment