Antonyms in Excel 365

donali

New Member
Joined
Oct 31, 2021
Messages
3
Office Version
  1. 365
Platform
  1. MacOS
Hello - I am trying to generate antonyms in Excel 365. Imagine in cells A1:A15 that I have 15 words. In B1:B15 I would like to see antonyms. I copied the code below from another thread on this site, but it doesn't seem to work, getting hung up on: Set mObjWord = CreateObject("word.application"). Does anyone have thoughts on this? Very much appreciated.

VBA Code:
Option Explicit
Private mObjWord As Object
 
Sub Antonyms()
Dim i As Long
Dim c As Range
Dim sWord As String
Dim arr
For Each c In Selection
    sWord = c
   
    If GetMeanings(sWord, arr) Then
    For i = LBound(arr) To UBound(arr)
        c.Offset(0, i).Value = arr(i)
    Next
   
    End If
Next c
Set mObjWord = Nothing 'clears the word object when done
End Sub
 
Function GetMeanings(myWord As String, vMeanings)
Dim objSynonymInfo As Object
If mObjWord Is Nothing Then
    Set mObjWord = CreateObject("word.application")
End If
Set objSynonymInfo = mObjWord.SynonymInfo(myWord)
vMeanings = objSynonymInfo.AntonymList
GetMeanings = UBound(vMeanings) > 0
End Function
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Don't know if this will work in 365, but have a look at this thread, in particular post #9
 
Upvote 0
It worked for me after I added the Microsoft Word 16.0 Object Library.

In the VBA editor, select Tools, References, then check the box for the aforementioned library, then try the code again with the cells with your words selected.
 
Upvote 0
I don't have Excel 365, but see if this works:

VBA Code:
Option Explicit

Private wdDoc               As Object
 
 
Sub Antonyms()
'
    Dim AntonymWordCounter  As Long
    Dim LastRowA            As Long
    Dim wdDoc               As Object
    Dim wdApp               As Object
    Dim Cel                 As Range
    Dim strGUID             As String
    Dim AntonymWord         As String
    Dim arr
'
    strGUID = "{00020905-0000-0000-C000-000000000046}"                      ' Microsoft Word reference
'
    On Error Resume Next
        ThisWorkbook.VBProject.References.AddFromGuid strGUID, 0, 0
    On Error GoTo 0
'
    Set wdApp = CreateObject("Word.Application")
    Set wdDoc = wdApp.Documents.Add
'
    LastRowA = Range("A" & Rows.Count).End(xlUp).Row
'
    For Each Cel In Range("A1:A" & LastRowA)
        AntonymWord = Cel
'
        If GetMeanings(AntonymWord, arr) Then
            For AntonymWordCounter = LBound(arr) To UBound(arr)
            Cel.Offset(0, AntonymWordCounter).Value = arr(AntonymWordCounter)
            Next
        End If
    Next
'
    Set wdDoc = Nothing                                                     'clears the word object when done
End Sub
 
Function GetMeanings(myWord As String, vMeanings)
'
    Dim objSynonymInfo As Object
'
    If wdDoc Is Nothing Then
        Set wdDoc = CreateObject("word.application")
    End If
'
    Set objSynonymInfo = wdDoc.SynonymInfo(myWord)
'
    vMeanings = objSynonymInfo.AntonymList
    GetMeanings = UBound(vMeanings) > 0
End Function
 
Upvote 0
Thanks for the replies. I have indeed checked the Microsoft Office 16.0 Object Library in References, and the original code that I posted doesn't work. Unfortunately johnnyL's code doesn't work either.

Specifically what happens with johnnyL's code:

1. A Microsoft Word window opens offering templates to choose, a list of my prior documents, and a Cancel or Creat option at the bottom right. Selecting Cancel makes it disappear, Create opens a blank document.

2. A VBA error box can be found under the above, showing this "Run-time error: Methos 'VBProject' of object '_Workbook' failed". Hitting the Debug button shows this highlighted in yellow in the code: Set wdApp = CreateObject("Word.Application")

Does it matter that I am using 365 for Mac? Really appreciate the help here.
 
Upvote 0
Forgive me - I should state that I have indeed checked the Microsoft Word 16.0 Object Library. Apologies for error. The things that are checked are:

Screenshot 2021-11-01 at 06.34.14.jpg
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top