Thread: [Solved] Acronym finder
View Single Post
 
Old 06-13-2019, 10:10 AM
maceslin maceslin is offline Windows 2K Office 2007
Novice
 
Join Date: Jul 2012
Posts: 8
maceslin is on a distinguished road
Default

I have modified the code slightly as I realized it was not drawing in acronyms that contained a number and am getting an error on the Set Matches line that state "application-defined or object define error. I suspect it is because I am no longer searching for just text. What is the member of range that include both text and numbers? Nothing jumps out at me

Code:
 
Sub Acronyms()
Dim dict, k, tmp
Dim regExp, Match, Matches
Dim oDoc As Document
    Set regExp = CreateObject("vbscript.regexp")
    Set dict = CreateObject("scripting.dictionary")
    regExp.Pattern = "\([A-Z][A-Za-z0-9]@\" '2 or more upper case letters/numbers
    regExp.IgnoreCase = False
    regExp.Global = True
    Set Matches = regExp.Execute(ActiveDocument.Range.Text)
    For Each Match In Matches
        tmp = Match.Value
        If Not dict.Exists(tmp) Then dict.Add tmp, 0
        dict(tmp) = dict(tmp) + 1
    Next
    Set oDoc = Documents.Add
    For Each k In dict.Keys
        'Debug.Print k, dict(k)
        oDoc.Range.InsertAfter k & ", " & dict(k) & vbCr
    Next k
    oDoc.Range.Paragraphs.Last.Range.Delete
    oDoc.Range.Sort
End Sub
Reply With Quote