View Single Post
 
Old 05-10-2018, 06:53 PM
Chrissy Chrissy is offline Windows 10 Office 2010 32bit
Novice
 
Join Date: May 2018
Posts: 2
Chrissy is on a distinguished road
Default Acronym Finder Assistance

Thank you. Can I please just verify in entirity:

Code:
Sub Acronyms()
Application.ScreenUpdating = False
Dim RngDoc As Range, oTbl As Table, i As Long, j As Long
Dim strAcr As String, strFnd As String, strDef As String
strAcr = ","
Set RngDoc = ActiveDocument.Range
With ActiveDocument
  Set oTbl = .Tables(INSERT TABLE NUMBER)
  RngDoc.Start = oTbl.Range.End
   For i = 2 To oTbl.Rows.Count
    With oTbl.Cell(i, 1).Range
      strFnd = Left(.Text, Len(.Text) - 2)
      strAcr = strAcr & strFnd & ","
    End With
  Next
  With RngDoc
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Format = False
      .Forward = True
      .Text = "\([A-Z][A-Za-z0-9]@\)"
      .MatchWildcards = True
      .Execute
    End With
    Do While .Find.Found
      .Start = .Start + 1
      .End = .End - 1
      strFnd = .Text
      If InStr(strAcr, "," & strFnd & ",") = 0 Then
        strAcr = strAcr & strFnd & ","
        strDef = Trim(InputBox("New Term Found: " & strFnd & vbCr & _
          "Add to definitions?" & vbCr & _
          "If yes, type the definition."))
        If strDef <> vbNullString Then
          With oTbl.Rows
            .Add
            .Last.Cells(1).Range.Text = strFnd
            .Last.Cells(2).Range.Text = strDef
          End With
        End If
      End If
      .Collapse wdCollapseEnd
      .Find.Execute
    Loop
  End With
  For i = oTbl.Rows.Count To 2 Step -1
    With oTbl.Cell(i, 2).Range
      strFnd = Left(.Text, Len(.Text) - 2)
    End With
    Set RngDoc = ActiveDocument.Range
    With RngDoc
      With .Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Format = False
        .Forward = True
        .Text = strFnd
        .MatchWholeWord = True
        .MatchWildcards = False
        .MatchCase = True
        .Execute
      End With
      j = 0
      Do While .Find.Found
        j = j + 1
        .Collapse wdCollapseEnd
        .Find.Execute
      Loop
    End With
      If j < 2 Then
        oTbl.Rows(i).Delete
      Else
        oTbl.Cell(i, 3).Range.Text = j - 1
      End If
  Next
End With
Set RngDoc = Nothing: Set oTbl = Nothing
Application.ScreenUpdating = True
End Sub

Last edited by macropod; 05-10-2018 at 06:55 PM. Reason: Added code tags
Reply With Quote