Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 09-05-2019, 08:35 PM
gmaxey gmaxey is offline How can I find my synonyms separately Windows 10 How can I find my synonyms separately Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

You can add a little polish to the output by leveraging the fact that a dictionary key and be a range object:

Code:
Sub ListSynonyms()
Dim oSynInfo As Object
Dim varList As Variant
Dim lngindex As Long, lngSyn As Long
Dim strSyns As String
Dim oDoc As Document, oDocReport As Document
Dim oRng As Range
Dim arrList() As String
Dim oDic As Object
Dim oKey
  Set oDic = CreateObject("Scripting.Dictionary")
  Application.ScreenUpdating = False
  Set oDoc = ActiveDocument
  Set oDocReport = Documents.Add
  Set oRng = oDoc.Range
  arrList = Split("layout|Content|many|Various|sometimes|use", "|")
  Set oRng = oDoc.Range
  With oRng.Find
    .Font.Bold = True
    While .Execute
      If Not oDic.Exists(oRng.Text) Then
        Set oSynInfo = oRng.SynonymInfo
        varList = oSynInfo.SynonymList(1)
        Select Case UBound(oSynInfo.SynonymList(1))
          Case 0
            strSyns = varList(0) & "."
          Case 1
            strSyns = varList(0) & " and " & varList(1) & "."
          Case Else
            For lngSyn = 1 To UBound(oSynInfo.SynonymList(1))
              Select Case lngSyn
                Case Is = 1: strSyns = varList(lngSyn)
                Case UBound(oSynInfo.SynonymList(1)): strSyns = strSyns & " and " & varList(lngSyn) & "."
                Case Else: strSyns = strSyns & ", " & varList(lngSyn)
              End Select
            Next
        End Select
        oDic.Add oRng.FormattedText, strSyns
        oRng.Collapse wdCollapseEnd
      End If
    Wend
  End With
  With oDocReport
    For Each oKey In oDic
      Set oRng = .Range
      With oRng
        .Collapse wdCollapseEnd
        .FormattedText = oKey
        .Collapse wdCollapseEnd
        .InsertAfter " - " & oDic.Item(oKey) & vbCr
        .Font.Bold = False
        .Paragraphs.Last.SpaceAfter = 12
      End With
    Next oKey
    .Paragraphs.Last.Range.Delete
    .Activate
  End With
  Application.ScreenUpdating = True
  Set oRng = Nothing: Set oDic = Nothing
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to trigger animations separately ? mj2000 PowerPoint 0 02-06-2019 10:10 AM
How can I find my synonyms separately How to write chapters separately with corresponding heading numbering bluejasmine Word 3 07-15-2018 07:21 AM
Check for value in each cell separately Jelmer Excel 4 07-06-2017 07:43 AM
Can we buy Access separately? eeaakkat Office 2 04-04-2017 08:28 PM
How can I find my synonyms separately Useless synonyms & other spell check complaints Vervaine Word 1 12-18-2016 06:37 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:02 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft