Class SynonymInfo (Word VBA)

The class SynonymInfo represents the information about synonyms, antonyms, related words, or related expressions for the specified range or a given string.

Set

To use a SynonymInfo class variable it first needs to be instantiated, for example

Dim sio as SynonymInfo
Set sio = Dim strWord As String: strWord = 
SynonymInfo(Word:=strWord)

The following procedures can be used to set variables of type SynonymInfo: Application.SynonymInfo and Range.SynonymInfo

AntonymList

Returns a list of antonyms for the word or phrase. The list is returned as an array of strings.

The AntonymList property is a property of the SynonymInfo object, which can be returned from either a range or the application. If this object is returned from the application, you specify the word to look up and the language to use. When the object is returned from a range, the range is looked up using the language of the range.

Dim arrayAntonyms As Variant 
Dim intLoop As Integer 
 
arrayAntonyms = SynonymInfo(Word:="big", _ 
 LanguageID:=wdEnglishUS).AntonymList 
For intLoop = 1 To UBound(arrayAntonyms) 
 MsgBox arrayAntonyms(intLoop) 
Next intLoop

Found

True if the thesaurus finds synonyms, antonyms, related words, or related expressions for the word or phrase.

Dim siTemp As SynonymInfo 
 
Set siTemp = SynonymInfo(Word:="authorize", _ 
 LanguageID:=wdEnglishUS) 
If siTemp.Found = True Then 
 Msgbox "The thesaurus has suggestions." 
Else 
 Msgbox "The thesaurus has no suggestions." 
End If

MeaningCount

Returns the number of entries in the list of meanings found in the thesaurus for the word or phrase. Returns 0 (zero) if no meanings were found.

Each meaning represents a unique list of synonyms for the word or phrase. The lists of related words, related expressions, and antonyms aren't counted as entries in the list of meanings.

Set mySynInfo = Selection.Range.SynonymInfo 
If mySynInfo.MeaningCount <> 0 Then 
 myList = mySynInfo.MeaningList 
 For i = 1 To Ubound(myList) 
 Debug.Print myList(i) 
 Next i 
Else 
 Msgbox "There were no meanings found." 
End If

MeaningList

Returns the list of meanings for the word or phrase. The list is returned as an array of strings.

The lists of related words, related expressions, and antonyms aren't counted as entries in the list of meanings.

Set mySyn = Documents("MyDoc.doc").Words(3).SynonymInfo 
If mySyn.MeaningCount <> 0 Then 
 myList = mySyn.MeaningList 
 For i = 1 To UBound(myList) 
 Msgbox myList(i) 
 Next i 
Else 
 Msgbox "There were no meanings found." 
End If

Parent

Returns an object that represents the parent object of the specified SynonymInfo object.

Dim objParent As Object
Set objParent = SynonymInfo.Parent

PartOfSpeechList

Returns a list of the parts of speech corresponding to the meanings found for the word or phrase looked up in the thesaurus. The list is returned as an array of integers.

Possible Values are wdAdjective - An adjective, wdAdverb - An adverb, wdConjunction - A conjunction, wdIdiom - An idiom, wdInterjection - An interjection, wdNoun - A noun, wdOther - Some other part of speech, wdPreposition - A preposition, wdPronoun - A pronoun, wdVerb - A verb.

The list of the parts of speech is returned as an array consisting of the following WdPartOfSpeech constants: wdAdjective, wdAdverb, wdConjunction, wdIdiom, wdInterjection, wdNoun, wdOther, wdPreposition, wdPronoun, and wdVerb. The array elements are ordered to correspond to the elements returned by the MeaningList property.

Set mySynInfo = Selection.Range.SynonymInfo 
If mySynInfo.MeaningCount <> 0 Then 
 myList = mySynInfo.MeaningList 
 myPos = mySynInfo.PartOfSpeechList 
 For i = 1 To UBound(myPos) 
 Select Case myPos(i) 
 Case wdAdjective 
 pos = "adjective" 
 Case wdNoun 
 pos = "noun" 
 Case wdAdverb 
 pos = "adverb" 
 Case wdVerb 
 pos = "verb" 
 Case Else 
 pos = "other" 
 End Select 
 MsgBox myList(i) & " found as " & pos 
 Next i 
Else 
 MsgBox "There were no meanings found." 
End If

RelatedExpressionList

Returns a list of expressions related to the specified word or phrase. The list is returned as an array of strings.

Typically, there are very few related expressions found in the thesaurus.

Set synInfo = Selection.Range.SynonymInfo 
If synInfo.Found = True Then 
 relList = synInfo.RelatedExpressionList 
 If UBound(relList) <> 0 Then 
 For intCount = 1 To UBound(relList) 
 Msgbox relList(intCount) 
 Next intCount 
 Else 
 Msgbox "There were no related expressions found." 
 End If 
End If

RelatedWordList

Returns a list of words related to the specified word or phrase. The list is returned as an array of strings.

Set synInfo = ActiveDocument.Words(3).SynonymInfo 
If synInfo.Found = True Then 
 relList = synInfo.RelatedWordList 
 If UBound(relList) <> 0 Then 
 For intCount = 1 To UBound(relList) 
 Msgbox relList(intCount) 
 Next intCount 
 Else 
 Msgbox "There were no related words found." 
 End If 
End If

SynonymList

Returns a list of synonyms for a specified meaning of a word or phrase. The list is returned as an array of strings.

Syntax : expression.SynonymList (Meaning)

Word

Returns the word or phrase that was looked up by the thesaurus.

The thesaurus will sometimes look up a shortened version of the string or range used to return the SynonymInfo object. The Word property allows you to see the exact string that was used.

Sub Syn() 
 Dim mySynObj As Object 
 Dim SList As Variant 
 Dim i As Variant 
 
 Set mySynObj = ActiveDocument.Words(3).SynonymInfo 
 SList = mySynObj.SynonymList(1) 
 For i = 1 To UBound(SList) 
 MsgBox "A synonym for " & mySynObj.Word _ 
 & " is " & SList(i) 
 Next i 
End Sub