Printing out a complete list of nouns, adjectives, adverbs, or verbs

John 466 Reputation points
2023-02-24T08:34:42.3+00:00

I would like to know more about how the Synonym Info class works.

I had wanted to buy more books on Word VBA, but it would be too expensive.

Can anyone provide me some examples?

Word
Word
A family of Microsoft word processing software products for creating web, email, and print documents.
842 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,896 questions
0 comments No comments
{count} votes

Accepted answer
  1. Alan Farias 750 Reputation points
    2023-02-24T16:05:09.64+00:00

    The SynonymInfo class is used to retrieve information about synonyms for a particular word or phrase. It has several properties and methods that allow you to get information about the synonyms, such as the number of synonyms, the synonyms themselves, and their part of speech.

    Here's an example of how to use the SynonymInfo class to get the synonyms for a particular word:

    Sub GetSynonyms()
        Dim synInfo As SynonymInfo
        Set synInfo = ActiveDocument.Range.SynonymInfo("happy", wdSynonymAntonym)
        If synInfo.MeaningCount > 0 Then
            Dim i As Integer
            For i = 1 To synInfo.MeaningCount
                Debug.Print "Meaning " & i & ":"
                Dim j As Integer
                For j = 1 To synInfo.MeaningList(i).Count
                    Debug.Print synInfo.MeaningList(i).Item(j)
                Next j
            Next i
        Else
            Debug.Print "No synonyms found."
        End If
    End Sub
    

    In this example, we use the SynonymInfo method to get the synonyms for the word "happy". We specify the wdSynonymAntonym constant as the second argument, which tells Word to return both synonyms and antonyms. We then check if there are any synonyms found, and if so, we loop through the list of meanings and the list of synonyms for each meaning, and output them to the Immediate window.

    Here's another example that uses the SynonymList property to get the synonyms for a word in a specific part of speech:

    Sub GetAdjectiveSynonyms()
        Dim synInfo As SynonymInfo
        Set synInfo = ActiveDocument.Range.SynonymInfo("happy", wdSynonymAdjective)
        If synInfo.SynonymCount > 0 Then
            Dim synList As Variant
            synList = synInfo.SynonymList
            Dim i As Integer
            For i = LBound(synList) To UBound(synList)
                Debug.Print synList(i)
            Next i
        Else
            Debug.Print "No synonyms found."
        End If
    End Sub
    

    In this example, we use the SynonymInfo method to get the synonyms for the adjective form of the word "happy". We specify the wdSynonymAdjective constant as the second argument, which tells Word to only return synonyms that are adjectives. We then get the list of synonyms using the SynonymList property, and output them to the Immediate window.

    I hope these examples help you understand how to use the SynonymInfo class in Word VBA. Let me know if you have any further questions!

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.