Thread: Synonym Finder
View Single Post
 
Old 04-28-2019, 12:14 AM
subrota subrota is offline Windows 10 Office 2013
Novice
 
Join Date: Apr 2019
Posts: 11
subrota is on a distinguished road
Default Synonym Finder

Synonyms Finder in MS Word
Requirements
  • To be written as MS word 2016 Macros
  • Will find synonyms from the MS word thesaurus and from a user defined thesaurus
  • In MS word, user will select (say with mouse) text having multiple paragraphs
  • In these paragraph there will be target words in bold (or underlined)
  • Based on user action, such as use of a shortcut key, a list of synonyms for each target word will be returned
  • Synonyms will be fetched from two sources 1) user defined 2) MS word resident Thesaurus
  • User defined synonym can come from a simple text file or excel sheet
  • After fetching the synonyms, the macro will return a user selection window, where all the synonyms with respective words will be displayed so that user can select which synonyms ultimately outputted
  • Selection window will display the synonyms for each target word followed by the respective target word
  • Selection window will not show duplicates
  • In the selection window default selection for user defined synonyms is "selected" and default selection for synonym from MS word thesaurus is "unselected". User can alter the selection by mouse click
  • After the user selection, the selected synonyms will be returned, grouped together with their respective target word.
  • Synonyms from the user defined source will be shown at the beginning of each group
  • The output can be return after the selected text
  • Returned synonyms will take care of various forms of the word (this requirement can be deferred for now)

Example

Text to be selected
===============
A computer is a device that can be instructed to carry out sequences of arithmetic or logical operations automatically via computer programming. We cannot live without computer


The synonyms for the bold/target words are following

Target word: computer
User defined synonyms: Processor, supercomputer, workstation, CPU
MS word synonyms: Processor, microprocessor, motherboard


The selection window will display the following (this is one way)
Computer
• Processor
• Microprocessor
• Motherboard
o Supercomputer
o Workstation
o CPU


After user selection
Computer
• Processor
• Microprocessor
o Motherboard
o Supercomputer
• Workstation
o CPU

Synonym Code:
Code:
Sub Synonyms_List()
Dim mySynObj As Object
Dim SList As Variant
Dim i As Long
Dim StrOut As String


Selection.MoveLeft Unit:=wdWord, Count:=1
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend

Set mySynObj = Selection.Range.SynonymInfo
    SList = mySynObj.SynonymList(1)
For i = 1 To UBound(mySynObj.SynonymList(1))
  StrOut = StrOut & vbCr & SList(i)
Next i
'MsgBox "Synonyms for " & mySynObj.Word & " are:" & StrOut

Dim strClipText As DataObject
Dim strInputText As String
Dim errCode As Integer

Set strClipText = New DataObject

strInputText = StrOut

strClipText.SetText strInputText
strClipText.PutInClipboard

Documents.Add

Selection.PasteAndFormat (wdFormatOriginalFormatting)

End Sub
Targeted Word Code:
Code:
Sub target_word()
Selection.HomeKey Unit:=wdStory
'    Selection.Find.ClearFormatting
    Selection.Find.Font.Bold = True
    Selection.Find.Execute
    Selection.Copy
    Documents.Add 'Template:="Normal", NewTemplate:=False, DocumentType:=0
    Selection.PasteAndFormat (wdFormatOriginalFormatting)
    Selection.TypeParagraph
    windows(2).Activate
'    Selection.Find.ClearFormatting
'    Selection.Find.Font.Bold = True
    
    
    Do While Selection.Find.Execute
    Selection.Copy
    windows(1).Activate
    Selection.PasteAndFormat (wdFormatOriginalFormatting)
    Selection.TypeParagraph
    windows(2).Activate
    Loop
End Sub
Attached Files
File Type: docx SynonymsFinder.docx (17.9 KB, 9 views)
Reply With Quote